[Ragile]Adapt kernel 5.10 for broadcom on RA-B6510-48V8C (#14809)

* Adapt kernel 5.10 for broadcom on RA-B6510-48V4C

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* update

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* update

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* update

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* update

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* modify one-image.mk file

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* modify debian/rule.mk

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

* Add platform.json file

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>

---------

Signed-off-by: pettershao-ragilenetworks <pettershao@ragilenetworks.com>
This commit is contained in:
pettershao-ragilenetworks 2023-08-05 03:01:49 +08:00 committed by GitHub
parent b11c6d47ea
commit abccdaeb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
350 changed files with 90818 additions and 25991 deletions

View File

@ -1,57 +1,57 @@
# name lanes alias index speed admin_status
Ethernet1 1 twentyfiveGigE0/1 0 25000 up
Ethernet2 2 twentyfiveGigE0/2 1 25000 up
Ethernet3 3 twentyfiveGigE0/3 2 25000 up
Ethernet4 4 twentyfiveGigE0/4 3 25000 up
Ethernet5 5 twentyfiveGigE0/5 4 25000 up
Ethernet6 6 twentyfiveGigE0/6 5 25000 up
Ethernet7 7 twentyfiveGigE0/7 6 25000 up
Ethernet8 8 twentyfiveGigE0/8 7 25000 up
Ethernet9 13 twentyfiveGigE0/9 8 25000 up
Ethernet10 14 twentyfiveGigE0/10 9 25000 up
Ethernet11 15 twentyfiveGigE0/11 10 25000 up
Ethernet12 16 twentyfiveGigE0/12 11 25000 up
Ethernet13 21 twentyfiveGigE0/13 12 25000 up
Ethernet14 22 twentyfiveGigE0/14 13 25000 up
Ethernet15 23 twentyfiveGigE0/15 14 25000 up
Ethernet16 24 twentyfiveGigE0/16 15 25000 up
Ethernet17 29 twentyfiveGigE0/17 16 25000 up
Ethernet18 30 twentyfiveGigE0/18 17 25000 up
Ethernet19 31 twentyfiveGigE0/19 18 25000 up
Ethernet20 32 twentyfiveGigE0/20 19 25000 up
Ethernet21 33 twentyfiveGigE0/21 20 25000 up
Ethernet22 34 twentyfiveGigE0/22 21 25000 up
Ethernet23 35 twentyfiveGigE0/23 22 25000 up
Ethernet24 36 twentyfiveGigE0/24 23 25000 up
Ethernet25 41 twentyfiveGigE0/25 24 25000 up
Ethernet26 42 twentyfiveGigE0/26 25 25000 up
Ethernet27 43 twentyfiveGigE0/27 26 25000 up
Ethernet28 44 twentyfiveGigE0/28 27 25000 up
Ethernet29 49 twentyfiveGigE0/29 28 25000 up
Ethernet30 50 twentyfiveGigE0/30 29 25000 up
Ethernet31 51 twentyfiveGigE0/31 30 25000 up
Ethernet32 52 twentyfiveGigE0/32 31 25000 up
Ethernet33 57 twentyfiveGigE0/33 32 25000 up
Ethernet34 58 twentyfiveGigE0/34 33 25000 up
Ethernet35 59 twentyfiveGigE0/35 34 25000 up
Ethernet36 60 twentyfiveGigE0/36 35 25000 up
Ethernet37 61 twentyfiveGigE0/37 36 25000 up
Ethernet38 62 twentyfiveGigE0/38 37 25000 up
Ethernet39 63 twentyfiveGigE0/39 38 25000 up
Ethernet40 64 twentyfiveGigE0/40 39 25000 up
Ethernet41 65 twentyfiveGigE0/41 40 25000 up
Ethernet42 66 twentyfiveGigE0/42 41 25000 up
Ethernet43 67 twentyfiveGigE0/43 42 25000 up
Ethernet44 68 twentyfiveGigE0/44 43 25000 up
Ethernet45 69 twentyfiveGigE0/45 44 25000 up
Ethernet46 70 twentyfiveGigE0/46 45 25000 up
Ethernet47 71 twentyfiveGigE0/47 46 25000 up
Ethernet48 72 twentyfiveGigE0/48 47 25000 up
Ethernet49 85,86,87,88 hundredGigE0/1 48 100000 up
Ethernet50 77,78,79,80 hundredGigE0/2 49 100000 up
Ethernet51 97,98,99,100 hundredGigE0/3 50 100000 up
Ethernet52 93,94,95,96 hundredGigE0/4 51 100000 up
Ethernet53 113,114,115,116 hundredGigE0/5 52 100000 up
Ethernet54 105,106,107,108 hundredGigE0/6 53 100000 up
Ethernet55 121,122,123,124 hundredGigE0/7 54 100000 up
Ethernet56 125,126,127,128 hundredGigE0/8 55 100000 up
# name lanes alias index speed admin_status
Ethernet1 57 twentyfiveGigE0/1 1 25000 up
Ethernet2 58 twentyfiveGigE0/2 2 25000 up
Ethernet3 59 twentyfiveGigE0/3 3 25000 up
Ethernet4 60 twentyfiveGigE0/4 4 25000 up
Ethernet5 61 twentyfiveGigE0/5 5 25000 up
Ethernet6 62 twentyfiveGigE0/6 6 25000 up
Ethernet7 63 twentyfiveGigE0/7 7 25000 up
Ethernet8 64 twentyfiveGigE0/8 8 25000 up
Ethernet9 1 twentyfiveGigE0/9 9 25000 up
Ethernet10 2 twentyfiveGigE0/10 10 25000 up
Ethernet11 3 twentyfiveGigE0/11 11 25000 up
Ethernet12 4 twentyfiveGigE0/12 12 25000 up
Ethernet13 5 twentyfiveGigE0/13 13 25000 up
Ethernet14 6 twentyfiveGigE0/14 14 25000 up
Ethernet15 7 twentyfiveGigE0/15 15 25000 up
Ethernet16 8 twentyfiveGigE0/16 16 25000 up
Ethernet17 13 twentyfiveGigE0/17 17 25000 up
Ethernet18 14 twentyfiveGigE0/18 18 25000 up
Ethernet19 15 twentyfiveGigE0/19 19 25000 up
Ethernet20 16 twentyfiveGigE0/20 20 25000 up
Ethernet21 21 twentyfiveGigE0/21 21 25000 up
Ethernet22 22 twentyfiveGigE0/22 22 25000 up
Ethernet23 23 twentyfiveGigE0/23 23 25000 up
Ethernet24 24 twentyfiveGigE0/24 24 25000 up
Ethernet25 29 twentyfiveGigE0/25 25 25000 up
Ethernet26 30 twentyfiveGigE0/26 26 25000 up
Ethernet27 31 twentyfiveGigE0/27 27 25000 up
Ethernet28 32 twentyfiveGigE0/28 28 25000 up
Ethernet29 33 twentyfiveGigE0/29 29 25000 up
Ethernet30 34 twentyfiveGigE0/30 30 25000 up
Ethernet31 35 twentyfiveGigE0/31 31 25000 up
Ethernet32 36 twentyfiveGigE0/32 32 25000 up
Ethernet33 41 twentyfiveGigE0/33 33 25000 up
Ethernet34 42 twentyfiveGigE0/34 34 25000 up
Ethernet35 43 twentyfiveGigE0/35 35 25000 up
Ethernet36 44 twentyfiveGigE0/36 36 25000 up
Ethernet37 49 twentyfiveGigE0/37 37 25000 up
Ethernet38 50 twentyfiveGigE0/38 38 25000 up
Ethernet39 51 twentyfiveGigE0/39 39 25000 up
Ethernet40 52 twentyfiveGigE0/40 40 25000 up
Ethernet41 65 twentyfiveGigE0/41 41 25000 up
Ethernet42 66 twentyfiveGigE0/42 42 25000 up
Ethernet43 67 twentyfiveGigE0/43 43 25000 up
Ethernet44 68 twentyfiveGigE0/44 44 25000 up
Ethernet45 69 twentyfiveGigE0/45 45 25000 up
Ethernet46 70 twentyfiveGigE0/46 46 25000 up
Ethernet47 71 twentyfiveGigE0/47 47 25000 up
Ethernet48 72 twentyfiveGigE0/48 48 25000 up
Ethernet49 85,86,87,88 hundredGigE0/1 49 100000 up
Ethernet50 77,78,79,80 hundredGigE0/2 50 100000 up
Ethernet51 97,98,99,100 hundredGigE0/3 51 100000 up
Ethernet52 93,94,95,96 hundredGigE0/4 52 100000 up
Ethernet53 113,114,115,116 hundredGigE0/5 53 100000 up
Ethernet54 105,106,107,108 hundredGigE0/6 54 100000 up
Ethernet55 121,122,123,124 hundredGigE0/7 55 100000 up
Ethernet56 125,126,127,128 hundredGigE0/8 56 100000 up

View File

@ -5,6 +5,8 @@ l3_alpm_enable=2
ipv6_lpm_128b_enable=0x1
l2xmsg_mode=0
l3_max_ecmp_mode=1
svi_my_station_optimization=1
sai_nbr_bcast_ifp_optimized=2
bcm_num_cos=8
bcm_stat_interval=2000000
cdma_timeout_usec=3000000
@ -22,208 +24,58 @@ oversubscribe_mode=1
parity_enable=1
pbmp_gport_stack.0=0x0000000000000000000000000000000000000000000000000000000000000000
#pbmp_xport_xe.0=0x00000000000000000000000000000000888ffffffffffff9fffffffffffffffe
pbmp_xport_xe=0x488080808808087f9fe1e1e1fe1e1e1fe
phy_chain_rx_lane_map_physical{1.0}=0x1032
phy_chain_tx_lane_map_physical{1.0}=0x0123
phy_chain_rx_lane_map_physical{5.0}=0x1032
phy_chain_tx_lane_map_physical{5.0}=0x0123
phy_chain_rx_lane_map_physical{13.0}=0x1032
phy_chain_tx_lane_map_physical{13.0}=0x0123
phy_chain_rx_lane_map_physical{21.0}=0x1032
phy_chain_tx_lane_map_physical{21.0}=0x0123
phy_chain_rx_lane_map_physical{29.0}=0x1032
phy_chain_tx_lane_map_physical{29.0}=0x0123
phy_chain_rx_lane_map_physical{33.0}=0x1032
phy_chain_tx_lane_map_physical{33.0}=0x0123
phy_chain_rx_lane_map_physical{41.0}=0x1032
phy_chain_tx_lane_map_physical{41.0}=0x0123
phy_chain_rx_lane_map_physical{49.0}=0x1032
phy_chain_tx_lane_map_physical{49.0}=0x0123
phy_chain_rx_lane_map_physical{57.0}=0x1032
phy_chain_tx_lane_map_physical{57.0}=0x0123
phy_chain_rx_lane_map_physical{61.0}=0x1032
phy_chain_tx_lane_map_physical{61.0}=0x0123
phy_chain_rx_lane_map_physical{65.0}=0x2301
phy_chain_tx_lane_map_physical{65.0}=0x3210
phy_chain_rx_lane_map_physical{69.0}=0x2301
phy_chain_tx_lane_map_physical{69.0}=0x3210
phy_chain_rx_lane_map_physical{77.0}=0x1032
phy_chain_tx_lane_map_physical{77.0}=0x3210
phy_chain_rx_lane_map_physical{85.0}=0x1032
phy_chain_tx_lane_map_physical{85.0}=0x3210
phy_chain_rx_lane_map_physical{93.0}=0x1032
phy_chain_tx_lane_map_physical{93.0}=0x3210
phy_chain_rx_lane_map_physical{97.0}=0x1032
phy_chain_tx_lane_map_physical{97.0}=0x3210
phy_chain_rx_lane_map_physical{105.0}=0x1032
phy_chain_tx_lane_map_physical{105.0}=0x3210
phy_chain_rx_lane_map_physical{113.0}=0x1032
phy_chain_tx_lane_map_physical{113.0}=0x3210
phy_chain_rx_lane_map_physical{121.0}=0x2031
phy_chain_tx_lane_map_physical{121.0}=0x3210
phy_chain_rx_lane_map_physical{125.0}=0x1032
phy_chain_tx_lane_map_physical{125.0}=0x1203
phy_chain_tx_polarity_flip_physical{1.0}=0x1
phy_chain_rx_polarity_flip_physical{1.0}=0x0
phy_chain_tx_polarity_flip_physical{2.0}=0x0
phy_chain_rx_polarity_flip_physical{2.0}=0x0
phy_chain_tx_polarity_flip_physical{3.0}=0x1
phy_chain_rx_polarity_flip_physical{3.0}=0x0
phy_chain_tx_polarity_flip_physical{4.0}=0x0
phy_chain_rx_polarity_flip_physical{4.0}=0x0
phy_chain_tx_polarity_flip_physical{5.0}=0x1
phy_chain_rx_polarity_flip_physical{5.0}=0x0
phy_chain_tx_polarity_flip_physical{6.0}=0x0
phy_chain_rx_polarity_flip_physical{6.0}=0x0
phy_chain_tx_polarity_flip_physical{7.0}=0x1
phy_chain_rx_polarity_flip_physical{7.0}=0x0
phy_chain_tx_polarity_flip_physical{8.0}=0x0
phy_chain_rx_polarity_flip_physical{8.0}=0x0
phy_chain_tx_polarity_flip_physical{13.0}=0x0
phy_chain_rx_polarity_flip_physical{13.0}=0x0
phy_chain_tx_polarity_flip_physical{14.0}=0x0
phy_chain_rx_polarity_flip_physical{14.0}=0x0
phy_chain_tx_polarity_flip_physical{15.0}=0x0
phy_chain_rx_polarity_flip_physical{15.0}=0x0
phy_chain_tx_polarity_flip_physical{16.0}=0x0
phy_chain_rx_polarity_flip_physical{16.0}=0x0
phy_chain_tx_polarity_flip_physical{21.0}=0x1
phy_chain_rx_polarity_flip_physical{21.0}=0x0
phy_chain_tx_polarity_flip_physical{22.0}=0x0
phy_chain_rx_polarity_flip_physical{22.0}=0x0
phy_chain_tx_polarity_flip_physical{23.0}=0x1
phy_chain_rx_polarity_flip_physical{23.0}=0x0
phy_chain_tx_polarity_flip_physical{24.0}=0x0
phy_chain_rx_polarity_flip_physical{24.0}=0x0
phy_chain_tx_polarity_flip_physical{29.0}=0x0
phy_chain_rx_polarity_flip_physical{29.0}=0x1
phy_chain_tx_polarity_flip_physical{30.0}=0x0
phy_chain_rx_polarity_flip_physical{30.0}=0x1
phy_chain_tx_polarity_flip_physical{31.0}=0x0
phy_chain_rx_polarity_flip_physical{31.0}=0x1
phy_chain_tx_polarity_flip_physical{32.0}=0x0
phy_chain_rx_polarity_flip_physical{32.0}=0x1
phy_chain_tx_polarity_flip_physical{33.0}=0x0
phy_chain_rx_polarity_flip_physical{33.0}=0x0
phy_chain_tx_polarity_flip_physical{34.0}=0x0
phy_chain_rx_polarity_flip_physical{34.0}=0x0
phy_chain_tx_polarity_flip_physical{35.0}=0x0
phy_chain_rx_polarity_flip_physical{35.0}=0x0
phy_chain_tx_polarity_flip_physical{36.0}=0x0
phy_chain_rx_polarity_flip_physical{36.0}=0x0
phy_chain_tx_polarity_flip_physical{41.0}=0x0
phy_chain_rx_polarity_flip_physical{41.0}=0x0
phy_chain_tx_polarity_flip_physical{42.0}=0x0
phy_chain_rx_polarity_flip_physical{42.0}=0x0
phy_chain_tx_polarity_flip_physical{43.0}=0x0
phy_chain_rx_polarity_flip_physical{43.0}=0x0
phy_chain_tx_polarity_flip_physical{44.0}=0x0
phy_chain_rx_polarity_flip_physical{44.0}=0x0
phy_chain_tx_polarity_flip_physical{49.0}=0x0
phy_chain_rx_polarity_flip_physical{49.0}=0x0
phy_chain_tx_polarity_flip_physical{50.0}=0x0
phy_chain_rx_polarity_flip_physical{50.0}=0x0
phy_chain_tx_polarity_flip_physical{51.0}=0x0
phy_chain_rx_polarity_flip_physical{51.0}=0x0
phy_chain_tx_polarity_flip_physical{52.0}=0x0
phy_chain_rx_polarity_flip_physical{52.0}=0x0
phy_chain_tx_polarity_flip_physical{57.0}=0x0
phy_chain_rx_polarity_flip_physical{57.0}=0x0
phy_chain_tx_polarity_flip_physical{58.0}=0x0
phy_chain_rx_polarity_flip_physical{58.0}=0x0
phy_chain_tx_polarity_flip_physical{59.0}=0x0
phy_chain_rx_polarity_flip_physical{59.0}=0x0
phy_chain_tx_polarity_flip_physical{60.0}=0x0
phy_chain_rx_polarity_flip_physical{60.0}=0x0
phy_chain_tx_polarity_flip_physical{61.0}=0x0
phy_chain_rx_polarity_flip_physical{61.0}=0x1
phy_chain_tx_polarity_flip_physical{62.0}=0x0
phy_chain_rx_polarity_flip_physical{62.0}=0x1
phy_chain_tx_polarity_flip_physical{63.0}=0x0
phy_chain_rx_polarity_flip_physical{63.0}=0x1
phy_chain_tx_polarity_flip_physical{64.0}=0x0
phy_chain_rx_polarity_flip_physical{64.0}=0x1
phy_chain_tx_polarity_flip_physical{65.0}=0x0
phy_chain_rx_polarity_flip_physical{65.0}=0x1
phy_chain_tx_polarity_flip_physical{66.0}=0x0
phy_chain_rx_polarity_flip_physical{66.0}=0x1
phy_chain_tx_polarity_flip_physical{67.0}=0x0
phy_chain_rx_polarity_flip_physical{67.0}=0x1
phy_chain_tx_polarity_flip_physical{68.0}=0x0
phy_chain_rx_polarity_flip_physical{68.0}=0x1
phy_chain_tx_polarity_flip_physical{69.0}=0x0
phy_chain_rx_polarity_flip_physical{69.0}=0x0
phy_chain_tx_polarity_flip_physical{70.0}=0x0
phy_chain_rx_polarity_flip_physical{70.0}=0x0
phy_chain_tx_polarity_flip_physical{71.0}=0x0
phy_chain_rx_polarity_flip_physical{71.0}=0x0
phy_chain_tx_polarity_flip_physical{72.0}=0x0
phy_chain_rx_polarity_flip_physical{72.0}=0x0
phy_chain_tx_polarity_flip_physical{85.0}=0x1
phy_chain_rx_polarity_flip_physical{85.0}=0x1
phy_chain_tx_polarity_flip_physical{86.0}=0x0
phy_chain_rx_polarity_flip_physical{86.0}=0x1
phy_chain_tx_polarity_flip_physical{87.0}=0x1
phy_chain_rx_polarity_flip_physical{87.0}=0x1
phy_chain_tx_polarity_flip_physical{88.0}=0x0
phy_chain_rx_polarity_flip_physical{88.0}=0x1
phy_chain_tx_polarity_flip_physical{77.0}=0x1
phy_chain_rx_polarity_flip_physical{77.0}=0x1
phy_chain_tx_polarity_flip_physical{78.0}=0x1
phy_chain_rx_polarity_flip_physical{78.0}=0x0
phy_chain_tx_polarity_flip_physical{79.0}=0x1
phy_chain_rx_polarity_flip_physical{79.0}=0x1
phy_chain_tx_polarity_flip_physical{80.0}=0x1
phy_chain_rx_polarity_flip_physical{80.0}=0x1
phy_chain_tx_polarity_flip_physical{97.0}=0x1
phy_chain_rx_polarity_flip_physical{97.0}=0x0
phy_chain_tx_polarity_flip_physical{98.0}=0x0
phy_chain_rx_polarity_flip_physical{98.0}=0x0
phy_chain_tx_polarity_flip_physical{99.0}=0x1
phy_chain_rx_polarity_flip_physical{99.0}=0x0
phy_chain_tx_polarity_flip_physical{100.0}=0x0
phy_chain_rx_polarity_flip_physical{100.0}=0x0
phy_chain_tx_polarity_flip_physical{93.0}=0x1
phy_chain_rx_polarity_flip_physical{93.0}=0x1
phy_chain_tx_polarity_flip_physical{94.0}=0x1
phy_chain_rx_polarity_flip_physical{94.0}=0x0
phy_chain_tx_polarity_flip_physical{95.0}=0x1
phy_chain_rx_polarity_flip_physical{95.0}=0x1
phy_chain_tx_polarity_flip_physical{96.0}=0x1
phy_chain_rx_polarity_flip_physical{96.0}=0x1
phy_chain_tx_polarity_flip_physical{113.0}=0x1
phy_chain_rx_polarity_flip_physical{113.0}=0x1
phy_chain_tx_polarity_flip_physical{114.0}=0x0
phy_chain_rx_polarity_flip_physical{114.0}=0x1
phy_chain_tx_polarity_flip_physical{115.0}=0x1
phy_chain_rx_polarity_flip_physical{115.0}=0x1
phy_chain_tx_polarity_flip_physical{116.0}=0x0
phy_chain_rx_polarity_flip_physical{116.0}=0x1
phy_chain_tx_polarity_flip_physical{105.0}=0x1
phy_chain_rx_polarity_flip_physical{105.0}=0x1
phy_chain_tx_polarity_flip_physical{106.0}=0x1
phy_chain_rx_polarity_flip_physical{106.0}=0x0
phy_chain_tx_polarity_flip_physical{107.0}=0x1
phy_chain_rx_polarity_flip_physical{107.0}=0x1
phy_chain_tx_polarity_flip_physical{108.0}=0x1
phy_chain_rx_polarity_flip_physical{108.0}=0x1
phy_chain_tx_polarity_flip_physical{121.0}=0x1
phy_chain_rx_polarity_flip_physical{121.0}=0x1
phy_chain_tx_polarity_flip_physical{122.0}=0x0
phy_chain_rx_polarity_flip_physical{122.0}=0x0
phy_chain_tx_polarity_flip_physical{123.0}=0x1
phy_chain_rx_polarity_flip_physical{123.0}=0x0
phy_chain_tx_polarity_flip_physical{124.0}=0x0
phy_chain_rx_polarity_flip_physical{124.0}=0x1
phy_chain_tx_polarity_flip_physical{125.0}=0x0
phy_chain_rx_polarity_flip_physical{125.0}=0x0
phy_chain_tx_polarity_flip_physical{126.0}=0x1
phy_chain_rx_polarity_flip_physical{126.0}=0x1
phy_chain_tx_polarity_flip_physical{127.0}=0x0
phy_chain_rx_polarity_flip_physical{127.0}=0x0
phy_chain_tx_polarity_flip_physical{128.0}=0x0
phy_chain_rx_polarity_flip_physical{128.0}=0x0
pbmp_xport_xe=0xffffffffffffffffffffffffffffffffffffffffe
port_flex_enable=1
phy_chain_tx_lane_map_physical{57.0}=0x0123
phy_chain_tx_lane_map_physical{61.0}=0x0123
phy_chain_tx_lane_map_physical{1.0}=0x0123
phy_chain_tx_lane_map_physical{5.0}=0x0123
phy_chain_tx_lane_map_physical{13.0}=0x0123
phy_chain_tx_lane_map_physical{21.0}=0x0123
phy_chain_tx_lane_map_physical{29.0}=0x0123
phy_chain_tx_lane_map_physical{33.0}=0x0123
phy_chain_tx_lane_map_physical{41.0}=0x0123
phy_chain_tx_lane_map_physical{49.0}=0x0123
phy_chain_tx_lane_map_physical{65.0}=0x3210
phy_chain_tx_lane_map_physical{69.0}=0x3210
phy_chain_tx_lane_map_physical{85.0}=0x3210
phy_chain_tx_lane_map_physical{77.0}=0x0213
phy_chain_tx_lane_map_physical{97.0}=0x3210
phy_chain_tx_lane_map_physical{93.0}=0x0213
phy_chain_tx_lane_map_physical{113.0}=0x3210
phy_chain_tx_lane_map_physical{105.0}=0x0213
phy_chain_tx_lane_map_physical{121.0}=0x3120
phy_chain_tx_lane_map_physical{125.0}=0x1203
phy_chain_rx_lane_map_physical{57.0}=0x1032
phy_chain_rx_lane_map_physical{61.0}=0x1032
phy_chain_rx_lane_map_physical{1.0}=0x1032
phy_chain_rx_lane_map_physical{5.0}=0x1032
phy_chain_rx_lane_map_physical{13.0}=0x1032
phy_chain_rx_lane_map_physical{21.0}=0x1032
phy_chain_rx_lane_map_physical{29.0}=0x1032
phy_chain_rx_lane_map_physical{33.0}=0x1032
phy_chain_rx_lane_map_physical{41.0}=0x1032
phy_chain_rx_lane_map_physical{49.0}=0x1032
phy_chain_rx_lane_map_physical{65.0}=0x2301
phy_chain_rx_lane_map_physical{69.0}=0x2301
phy_chain_rx_lane_map_physical{85.0}=0x1032
phy_chain_rx_lane_map_physical{77.0}=0x1032
phy_chain_rx_lane_map_physical{97.0}=0x1032
phy_chain_rx_lane_map_physical{93.0}=0x1032
phy_chain_rx_lane_map_physical{113.0}=0x1032
phy_chain_rx_lane_map_physical{105.0}=0x1032
phy_chain_rx_lane_map_physical{121.0}=0x2031
phy_chain_rx_lane_map_physical{125.0}=0x1023
portmap_57=57:25
portmap_58=58:25
portmap_59=59:25
portmap_60=60:25
portmap_61=61:25
portmap_62=62:25
portmap_63=63:25
portmap_64=64:25
portmap_1=1:25
portmap_2=2:25
portmap_3=3:25
@ -256,14 +108,6 @@ portmap_49=49:25
portmap_50=50:25
portmap_51=51:25
portmap_52=52:25
portmap_57=57:25
portmap_58=58:25
portmap_59=59:25
portmap_60=60:25
portmap_61=61:25
portmap_62=62:25
portmap_63=63:25
portmap_64=64:25
portmap_67=65:25
portmap_68=66:25
portmap_69=67:25
@ -272,55 +116,55 @@ portmap_71=69:25
portmap_72=70:25
portmap_73=71:25
portmap_74=72:25
portmap_79=77:100
portmap_87=85:100
portmap_95=93:100
portmap_79=77:100
portmap_99=97:100
portmap_107=105:100
portmap_95=93:100
portmap_115=113:100
portmap_107=105:100
portmap_123=121:100
portmap_127=125:100
dport_map_port_1=1
dport_map_port_2=2
dport_map_port_3=3
dport_map_port_4=4
dport_map_port_5=5
dport_map_port_6=6
dport_map_port_7=7
dport_map_port_8=8
dport_map_port_13=9
dport_map_port_14=10
dport_map_port_15=11
dport_map_port_16=12
dport_map_port_21=13
dport_map_port_22=14
dport_map_port_23=15
dport_map_port_24=16
dport_map_port_29=17
dport_map_port_30=18
dport_map_port_31=19
dport_map_port_32=20
dport_map_port_33=21
dport_map_port_34=22
dport_map_port_35=23
dport_map_port_36=24
dport_map_port_41=25
dport_map_port_42=26
dport_map_port_43=27
dport_map_port_44=28
dport_map_port_49=29
dport_map_port_50=30
dport_map_port_51=31
dport_map_port_52=32
dport_map_port_57=33
dport_map_port_58=34
dport_map_port_59=35
dport_map_port_60=36
dport_map_port_61=37
dport_map_port_62=38
dport_map_port_63=39
dport_map_port_64=40
dport_map_port_57=1
dport_map_port_58=2
dport_map_port_59=3
dport_map_port_60=4
dport_map_port_61=5
dport_map_port_62=6
dport_map_port_63=7
dport_map_port_64=8
dport_map_port_1=9
dport_map_port_2=10
dport_map_port_3=11
dport_map_port_4=12
dport_map_port_5=13
dport_map_port_6=14
dport_map_port_7=15
dport_map_port_8=16
dport_map_port_13=17
dport_map_port_14=18
dport_map_port_15=19
dport_map_port_16=20
dport_map_port_21=21
dport_map_port_22=22
dport_map_port_23=23
dport_map_port_24=24
dport_map_port_29=25
dport_map_port_30=26
dport_map_port_31=27
dport_map_port_32=28
dport_map_port_33=29
dport_map_port_34=30
dport_map_port_35=31
dport_map_port_36=32
dport_map_port_41=33
dport_map_port_42=34
dport_map_port_43=35
dport_map_port_44=36
dport_map_port_49=37
dport_map_port_50=38
dport_map_port_51=39
dport_map_port_52=40
dport_map_port_67=41
dport_map_port_68=42
dport_map_port_69=43
@ -338,65 +182,421 @@ dport_map_port_107=54
dport_map_port_123=55
dport_map_port_127=56
serdes_if_type_1=13
serdes_if_type_2=13
serdes_if_type_3=13
serdes_if_type_4=13
serdes_if_type_5=13
serdes_if_type_6=13
serdes_if_type_7=13
serdes_if_type_8=13
serdes_if_type_13=13
serdes_if_type_14=13
serdes_if_type_15=13
serdes_if_type_16=13
serdes_if_type_21=13
serdes_if_type_22=13
serdes_if_type_23=13
serdes_if_type_24=13
serdes_if_type_29=13
serdes_if_type_30=13
serdes_if_type_31=13
serdes_if_type_32=13
serdes_if_type_33=13
serdes_if_type_34=13
serdes_if_type_35=13
serdes_if_type_36=13
serdes_if_type_41=13
serdes_if_type_42=13
serdes_if_type_43=13
serdes_if_type_44=13
serdes_if_type_49=13
serdes_if_type_50=13
serdes_if_type_51=13
serdes_if_type_52=13
serdes_if_type_57=13
serdes_if_type_58=13
serdes_if_type_59=13
serdes_if_type_60=13
serdes_if_type_61=13
serdes_if_type_62=13
serdes_if_type_63=13
serdes_if_type_64=13
serdes_if_type_67=13
serdes_if_type_68=13
serdes_if_type_69=13
serdes_if_type_70=13
serdes_if_type_71=13
serdes_if_type_72=13
serdes_if_type_73=13
serdes_if_type_74=13
serdes_if_type_87=14
serdes_if_type_79=14
serdes_if_type_99=14
serdes_if_type_95=14
serdes_if_type_115=14
serdes_if_type_107=14
serdes_if_type_123=14
serdes_if_type_127=14
phy_chain_tx_polarity_flip_physical{57.0}=0x1
phy_chain_tx_polarity_flip_physical{58.0}=0x0
phy_chain_tx_polarity_flip_physical{59.0}=0x1
phy_chain_tx_polarity_flip_physical{60.0}=0x0
phy_chain_tx_polarity_flip_physical{61.0}=0x1
phy_chain_tx_polarity_flip_physical{62.0}=0x0
phy_chain_tx_polarity_flip_physical{63.0}=0x1
phy_chain_tx_polarity_flip_physical{64.0}=0x0
phy_chain_tx_polarity_flip_physical{1.0}=0x0
phy_chain_tx_polarity_flip_physical{2.0}=0x0
phy_chain_tx_polarity_flip_physical{3.0}=0x0
phy_chain_tx_polarity_flip_physical{4.0}=0x0
phy_chain_tx_polarity_flip_physical{5.0}=0x0
phy_chain_tx_polarity_flip_physical{6.0}=0x0
phy_chain_tx_polarity_flip_physical{7.0}=0x0
phy_chain_tx_polarity_flip_physical{8.0}=0x0
phy_chain_tx_polarity_flip_physical{13.0}=0x0
phy_chain_tx_polarity_flip_physical{14.0}=0x0
phy_chain_tx_polarity_flip_physical{15.0}=0x0
phy_chain_tx_polarity_flip_physical{16.0}=0x0
phy_chain_tx_polarity_flip_physical{21.0}=0x0
phy_chain_tx_polarity_flip_physical{22.0}=0x0
phy_chain_tx_polarity_flip_physical{23.0}=0x0
phy_chain_tx_polarity_flip_physical{24.0}=0x0
phy_chain_tx_polarity_flip_physical{29.0}=0x0
phy_chain_tx_polarity_flip_physical{30.0}=0x0
phy_chain_tx_polarity_flip_physical{31.0}=0x0
phy_chain_tx_polarity_flip_physical{32.0}=0x0
phy_chain_tx_polarity_flip_physical{33.0}=0x0
phy_chain_tx_polarity_flip_physical{34.0}=0x0
phy_chain_tx_polarity_flip_physical{35.0}=0x0
phy_chain_tx_polarity_flip_physical{36.0}=0x0
phy_chain_tx_polarity_flip_physical{41.0}=0x0
phy_chain_tx_polarity_flip_physical{42.0}=0x0
phy_chain_tx_polarity_flip_physical{43.0}=0x0
phy_chain_tx_polarity_flip_physical{44.0}=0x0
phy_chain_tx_polarity_flip_physical{49.0}=0x0
phy_chain_tx_polarity_flip_physical{50.0}=0x0
phy_chain_tx_polarity_flip_physical{51.0}=0x0
phy_chain_tx_polarity_flip_physical{52.0}=0x0
phy_chain_tx_polarity_flip_physical{65.0}=0x0
phy_chain_tx_polarity_flip_physical{66.0}=0x0
phy_chain_tx_polarity_flip_physical{67.0}=0x0
phy_chain_tx_polarity_flip_physical{68.0}=0x0
phy_chain_tx_polarity_flip_physical{69.0}=0x0
phy_chain_tx_polarity_flip_physical{70.0}=0x0
phy_chain_tx_polarity_flip_physical{71.0}=0x0
phy_chain_tx_polarity_flip_physical{72.0}=0x0
phy_chain_tx_polarity_flip_physical{85.0}=0x0
phy_chain_tx_polarity_flip_physical{86.0}=0x0
phy_chain_tx_polarity_flip_physical{87.0}=0x1
phy_chain_tx_polarity_flip_physical{88.0}=0x0
phy_chain_tx_polarity_flip_physical{77.0}=0x1
phy_chain_tx_polarity_flip_physical{78.0}=0x0
phy_chain_tx_polarity_flip_physical{79.0}=0x1
phy_chain_tx_polarity_flip_physical{80.0}=0x0
phy_chain_tx_polarity_flip_physical{97.0}=0x0
phy_chain_tx_polarity_flip_physical{98.0}=0x0
phy_chain_tx_polarity_flip_physical{99.0}=0x1
phy_chain_tx_polarity_flip_physical{100.0}=0x0
phy_chain_tx_polarity_flip_physical{93.0}=0x0
phy_chain_tx_polarity_flip_physical{94.0}=0x1
phy_chain_tx_polarity_flip_physical{95.0}=0x1
phy_chain_tx_polarity_flip_physical{96.0}=0x0
phy_chain_tx_polarity_flip_physical{113.0}=0x0
phy_chain_tx_polarity_flip_physical{114.0}=0x0
phy_chain_tx_polarity_flip_physical{115.0}=0x1
phy_chain_tx_polarity_flip_physical{116.0}=0x0
phy_chain_tx_polarity_flip_physical{105.0}=0x0
phy_chain_tx_polarity_flip_physical{106.0}=0x1
phy_chain_tx_polarity_flip_physical{107.0}=0x1
phy_chain_tx_polarity_flip_physical{108.0}=0x0
phy_chain_tx_polarity_flip_physical{121.0}=0x1
phy_chain_tx_polarity_flip_physical{122.0}=0x0
phy_chain_tx_polarity_flip_physical{123.0}=0x1
phy_chain_tx_polarity_flip_physical{124.0}=0x0
phy_chain_tx_polarity_flip_physical{125.0}=0x1
phy_chain_tx_polarity_flip_physical{126.0}=0x0
phy_chain_tx_polarity_flip_physical{127.0}=0x1
phy_chain_tx_polarity_flip_physical{128.0}=0x1
phy_chain_rx_polarity_flip_physical{57.0}=0x0
phy_chain_rx_polarity_flip_physical{58.0}=0x0
phy_chain_rx_polarity_flip_physical{59.0}=0x0
phy_chain_rx_polarity_flip_physical{60.0}=0x0
phy_chain_rx_polarity_flip_physical{61.0}=0x1
phy_chain_rx_polarity_flip_physical{62.0}=0x1
phy_chain_rx_polarity_flip_physical{63.0}=0x1
phy_chain_rx_polarity_flip_physical{64.0}=0x1
phy_chain_rx_polarity_flip_physical{1.0}=0x1
phy_chain_rx_polarity_flip_physical{2.0}=0x1
phy_chain_rx_polarity_flip_physical{3.0}=0x1
phy_chain_rx_polarity_flip_physical{4.0}=0x1
phy_chain_rx_polarity_flip_physical{5.0}=0x0
phy_chain_rx_polarity_flip_physical{6.0}=0x0
phy_chain_rx_polarity_flip_physical{7.0}=0x0
phy_chain_rx_polarity_flip_physical{8.0}=0x0
phy_chain_rx_polarity_flip_physical{13.0}=0x0
phy_chain_rx_polarity_flip_physical{14.0}=0x0
phy_chain_rx_polarity_flip_physical{15.0}=0x0
phy_chain_rx_polarity_flip_physical{16.0}=0x0
phy_chain_rx_polarity_flip_physical{21.0}=0x0
phy_chain_rx_polarity_flip_physical{22.0}=0x0
phy_chain_rx_polarity_flip_physical{23.0}=0x0
phy_chain_rx_polarity_flip_physical{24.0}=0x0
phy_chain_rx_polarity_flip_physical{29.0}=0x0
phy_chain_rx_polarity_flip_physical{30.0}=0x1
phy_chain_rx_polarity_flip_physical{31.0}=0x0
phy_chain_rx_polarity_flip_physical{32.0}=0x0
phy_chain_rx_polarity_flip_physical{33.0}=0x1
phy_chain_rx_polarity_flip_physical{34.0}=0x1
phy_chain_rx_polarity_flip_physical{35.0}=0x1
phy_chain_rx_polarity_flip_physical{36.0}=0x1
phy_chain_rx_polarity_flip_physical{41.0}=0x1
phy_chain_rx_polarity_flip_physical{42.0}=0x1
phy_chain_rx_polarity_flip_physical{43.0}=0x1
phy_chain_rx_polarity_flip_physical{44.0}=0x1
phy_chain_rx_polarity_flip_physical{49.0}=0x1
phy_chain_rx_polarity_flip_physical{50.0}=0x1
phy_chain_rx_polarity_flip_physical{51.0}=0x1
phy_chain_rx_polarity_flip_physical{52.0}=0x1
phy_chain_rx_polarity_flip_physical{65.0}=0x1
phy_chain_rx_polarity_flip_physical{66.0}=0x1
phy_chain_rx_polarity_flip_physical{67.0}=0x1
phy_chain_rx_polarity_flip_physical{68.0}=0x1
phy_chain_rx_polarity_flip_physical{69.0}=0x0
phy_chain_rx_polarity_flip_physical{70.0}=0x0
phy_chain_rx_polarity_flip_physical{71.0}=0x0
phy_chain_rx_polarity_flip_physical{72.0}=0x0
phy_chain_rx_polarity_flip_physical{85.0}=0x1
phy_chain_rx_polarity_flip_physical{86.0}=0x1
phy_chain_rx_polarity_flip_physical{87.0}=0x1
phy_chain_rx_polarity_flip_physical{88.0}=0x1
phy_chain_rx_polarity_flip_physical{77.0}=0x0
phy_chain_rx_polarity_flip_physical{78.0}=0x0
phy_chain_rx_polarity_flip_physical{79.0}=0x0
phy_chain_rx_polarity_flip_physical{80.0}=0x0
phy_chain_rx_polarity_flip_physical{97.0}=0x0
phy_chain_rx_polarity_flip_physical{98.0}=0x0
phy_chain_rx_polarity_flip_physical{99.0}=0x0
phy_chain_rx_polarity_flip_physical{100.0}=0x0
phy_chain_rx_polarity_flip_physical{93.0}=0x0
phy_chain_rx_polarity_flip_physical{94.0}=0x0
phy_chain_rx_polarity_flip_physical{95.0}=0x0
phy_chain_rx_polarity_flip_physical{96.0}=0x0
phy_chain_rx_polarity_flip_physical{113.0}=0x1
phy_chain_rx_polarity_flip_physical{114.0}=0x1
phy_chain_rx_polarity_flip_physical{115.0}=0x1
phy_chain_rx_polarity_flip_physical{116.0}=0x1
phy_chain_rx_polarity_flip_physical{105.0}=0x0
phy_chain_rx_polarity_flip_physical{106.0}=0x0
phy_chain_rx_polarity_flip_physical{107.0}=0x0
phy_chain_rx_polarity_flip_physical{108.0}=0x0
phy_chain_rx_polarity_flip_physical{121.0}=0x1
phy_chain_rx_polarity_flip_physical{122.0}=0x1
phy_chain_rx_polarity_flip_physical{123.0}=0x0
phy_chain_rx_polarity_flip_physical{124.0}=0x1
phy_chain_rx_polarity_flip_physical{125.0}=0x1
phy_chain_rx_polarity_flip_physical{126.0}=0x0
phy_chain_rx_polarity_flip_physical{127.0}=0x0
phy_chain_rx_polarity_flip_physical{128.0}=0x0
serdes_preemphasis_lane0_57=0x0f480d
serdes_preemphasis_lane1_57=0x0f480d
serdes_preemphasis_lane2_57=0x0f480d
serdes_preemphasis_lane3_57=0x0f480d
serdes_preemphasis_lane0_58=0x0f480d
serdes_preemphasis_lane1_58=0x0f480d
serdes_preemphasis_lane2_58=0x0f480d
serdes_preemphasis_lane3_58=0x0f480d
serdes_preemphasis_lane0_59=0x0f480d
serdes_preemphasis_lane1_59=0x0f480d
serdes_preemphasis_lane2_59=0x0f480d
serdes_preemphasis_lane3_59=0x0f480d
serdes_preemphasis_lane0_60=0x0f480d
serdes_preemphasis_lane1_60=0x0f480d
serdes_preemphasis_lane2_60=0x0f480d
serdes_preemphasis_lane3_60=0x0f480d
serdes_preemphasis_lane0_61=0x0f480d
serdes_preemphasis_lane1_61=0x0f480d
serdes_preemphasis_lane2_61=0x0f480d
serdes_preemphasis_lane3_61=0x0f480d
serdes_preemphasis_lane0_62=0x0f480d
serdes_preemphasis_lane1_62=0x0f480d
serdes_preemphasis_lane2_62=0x0f480d
serdes_preemphasis_lane3_62=0x0f480d
serdes_preemphasis_lane0_63=0x0f480d
serdes_preemphasis_lane1_63=0x0f480d
serdes_preemphasis_lane2_63=0x0f480d
serdes_preemphasis_lane3_63=0x0f480d
serdes_preemphasis_lane0_64=0x0f480d
serdes_preemphasis_lane1_64=0x0f480d
serdes_preemphasis_lane2_64=0x0f480d
serdes_preemphasis_lane3_64=0x0f480d
serdes_preemphasis_lane0_1=0x0f480d
serdes_preemphasis_lane1_1=0x0f480d
serdes_preemphasis_lane2_1=0x0f480d
serdes_preemphasis_lane3_1=0x0f480d
serdes_preemphasis_lane0_2=0x0d4b0c
serdes_preemphasis_lane1_2=0x0d4b0c
serdes_preemphasis_lane2_2=0x0d4b0c
serdes_preemphasis_lane3_2=0x0d4b0c
serdes_preemphasis_lane0_3=0x0f480d
serdes_preemphasis_lane1_3=0x0f480d
serdes_preemphasis_lane2_3=0x0f480d
serdes_preemphasis_lane3_3=0x0f480d
serdes_preemphasis_lane0_4=0x0d4b0c
serdes_preemphasis_lane1_4=0x0d4b0c
serdes_preemphasis_lane2_4=0x0d4b0c
serdes_preemphasis_lane3_4=0x0d4b0c
serdes_preemphasis_lane0_5=0x0f480d
serdes_preemphasis_lane1_5=0x0f480d
serdes_preemphasis_lane2_5=0x0f480d
serdes_preemphasis_lane3_5=0x0f480d
serdes_preemphasis_lane0_6=0x0d4b0c
serdes_preemphasis_lane1_6=0x0d4b0c
serdes_preemphasis_lane2_6=0x0d4b0c
serdes_preemphasis_lane3_6=0x0d4b0c
serdes_preemphasis_lane0_7=0x0f480d
serdes_preemphasis_lane1_7=0x0f480d
serdes_preemphasis_lane2_7=0x0f480d
serdes_preemphasis_lane3_7=0x0f480d
serdes_preemphasis_lane0_8=0x0d4b0c
serdes_preemphasis_lane1_8=0x0d4b0c
serdes_preemphasis_lane2_8=0x0d4b0c
serdes_preemphasis_lane3_8=0x0d4b0c
serdes_preemphasis_lane0_13=0x0f480d
serdes_preemphasis_lane1_13=0x0f480d
serdes_preemphasis_lane2_13=0x0f480d
serdes_preemphasis_lane3_13=0x0f480d
serdes_preemphasis_lane0_14=0x0d4b0c
serdes_preemphasis_lane1_14=0x0d4b0c
serdes_preemphasis_lane2_14=0x0d4b0c
serdes_preemphasis_lane3_14=0x0d4b0c
serdes_preemphasis_lane0_15=0x0f480d
serdes_preemphasis_lane1_15=0x0f480d
serdes_preemphasis_lane2_15=0x0f480d
serdes_preemphasis_lane3_15=0x0f480d
serdes_preemphasis_lane0_16=0x0d4b0c
serdes_preemphasis_lane1_16=0x0d4b0c
serdes_preemphasis_lane2_16=0x0d4b0c
serdes_preemphasis_lane3_16=0x0d4b0c
serdes_preemphasis_lane0_21=0x0d4b0c
serdes_preemphasis_lane1_21=0x0d4b0c
serdes_preemphasis_lane2_21=0x0d4b0c
serdes_preemphasis_lane3_21=0x0d4b0c
serdes_preemphasis_lane0_22=0x0d4b0c
serdes_preemphasis_lane1_22=0x0d4b0c
serdes_preemphasis_lane2_22=0x0d4b0c
serdes_preemphasis_lane3_22=0x0d4b0c
serdes_preemphasis_lane0_23=0x0d4b0c
serdes_preemphasis_lane1_23=0x0d4b0c
serdes_preemphasis_lane2_23=0x0d4b0c
serdes_preemphasis_lane3_23=0x0d4b0c
serdes_preemphasis_lane0_24=0x0d4b0c
serdes_preemphasis_lane1_24=0x0d4b0c
serdes_preemphasis_lane2_24=0x0d4b0c
serdes_preemphasis_lane3_24=0x0d4b0c
serdes_preemphasis_lane0_29=0x0d4b0c
serdes_preemphasis_lane1_29=0x0d4b0c
serdes_preemphasis_lane2_29=0x0d4b0c
serdes_preemphasis_lane3_29=0x0d4b0c
serdes_preemphasis_lane0_30=0x0d4b0c
serdes_preemphasis_lane1_30=0x0d4b0c
serdes_preemphasis_lane2_30=0x0d4b0c
serdes_preemphasis_lane3_30=0x0d4b0c
serdes_preemphasis_lane0_31=0x0d4b0c
serdes_preemphasis_lane1_31=0x0d4b0c
serdes_preemphasis_lane2_31=0x0d4b0c
serdes_preemphasis_lane3_31=0x0d4b0c
serdes_preemphasis_lane0_32=0x0d4b0c
serdes_preemphasis_lane1_32=0x0d4b0c
serdes_preemphasis_lane2_32=0x0d4b0c
serdes_preemphasis_lane3_32=0x0d4b0c
serdes_preemphasis_lane0_33=0x0d4b0c
serdes_preemphasis_lane1_33=0x0d4b0c
serdes_preemphasis_lane2_33=0x0d4b0c
serdes_preemphasis_lane3_33=0x0d4b0c
serdes_preemphasis_lane0_34=0x0d4b0c
serdes_preemphasis_lane1_34=0x0d4b0c
serdes_preemphasis_lane2_34=0x0d4b0c
serdes_preemphasis_lane3_34=0x0d4b0c
serdes_preemphasis_lane0_35=0x0d4b0c
serdes_preemphasis_lane1_35=0x0d4b0c
serdes_preemphasis_lane2_35=0x0d4b0c
serdes_preemphasis_lane3_35=0x0d4b0c
serdes_preemphasis_lane0_36=0x0d4b0c
serdes_preemphasis_lane1_36=0x0d4b0c
serdes_preemphasis_lane2_36=0x0d4b0c
serdes_preemphasis_lane3_36=0x0d4b0c
serdes_preemphasis_lane0_41=0x0d4b0c
serdes_preemphasis_lane1_41=0x0d4b0c
serdes_preemphasis_lane2_41=0x0d4b0c
serdes_preemphasis_lane3_41=0x0d4b0c
serdes_preemphasis_lane0_42=0x0d4b0c
serdes_preemphasis_lane1_42=0x0d4b0c
serdes_preemphasis_lane2_42=0x0d4b0c
serdes_preemphasis_lane3_42=0x0d4b0c
serdes_preemphasis_lane0_43=0x0d4b0c
serdes_preemphasis_lane1_43=0x0d4b0c
serdes_preemphasis_lane2_43=0x0d4b0c
serdes_preemphasis_lane3_43=0x0d4b0c
serdes_preemphasis_lane0_44=0x0d4b0c
serdes_preemphasis_lane1_44=0x0d4b0c
serdes_preemphasis_lane2_44=0x0d4b0c
serdes_preemphasis_lane3_44=0x0d4b0c
serdes_preemphasis_lane0_49=0x0f480d
serdes_preemphasis_lane1_49=0x0f480d
serdes_preemphasis_lane2_49=0x0f480d
serdes_preemphasis_lane3_49=0x0f480d
serdes_preemphasis_lane0_50=0x0d4b0c
serdes_preemphasis_lane1_50=0x0d4b0c
serdes_preemphasis_lane2_50=0x0d4b0c
serdes_preemphasis_lane3_50=0x0d4b0c
serdes_preemphasis_lane0_51=0x0f480d
serdes_preemphasis_lane1_51=0x0f480d
serdes_preemphasis_lane2_51=0x0f480d
serdes_preemphasis_lane3_51=0x0f480d
serdes_preemphasis_lane0_52=0x0d4b0c
serdes_preemphasis_lane1_52=0x0d4b0c
serdes_preemphasis_lane2_52=0x0d4b0c
serdes_preemphasis_lane3_52=0x0d4b0c
serdes_preemphasis_lane0_67=0x0d4b0c
serdes_preemphasis_lane1_67=0x0d4b0c
serdes_preemphasis_lane2_67=0x0d4b0c
serdes_preemphasis_lane3_67=0x0d4b0c
serdes_preemphasis_lane0_68=0x0d4b0c
serdes_preemphasis_lane1_68=0x0d4b0c
serdes_preemphasis_lane2_68=0x0d4b0c
serdes_preemphasis_lane3_68=0x0d4b0c
serdes_preemphasis_lane0_69=0x0d4b0c
serdes_preemphasis_lane1_69=0x0d4b0c
serdes_preemphasis_lane2_69=0x0d4b0c
serdes_preemphasis_lane3_69=0x0d4b0c
serdes_preemphasis_lane0_70=0x0d4b0c
serdes_preemphasis_lane1_70=0x0d4b0c
serdes_preemphasis_lane2_70=0x0d4b0c
serdes_preemphasis_lane3_70=0x0d4b0c
serdes_preemphasis_lane0_71=0x0d4b0c
serdes_preemphasis_lane1_71=0x0d4b0c
serdes_preemphasis_lane2_71=0x0d4b0c
serdes_preemphasis_lane3_71=0x0d4b0c
serdes_preemphasis_lane0_72=0x0d4b0c
serdes_preemphasis_lane1_72=0x0d4b0c
serdes_preemphasis_lane2_72=0x0d4b0c
serdes_preemphasis_lane3_72=0x0d4b0c
serdes_preemphasis_lane0_73=0x0d4b0c
serdes_preemphasis_lane1_73=0x0d4b0c
serdes_preemphasis_lane2_73=0x0d4b0c
serdes_preemphasis_lane3_73=0x0d4b0c
serdes_preemphasis_lane0_74=0x0d4b0c
serdes_preemphasis_lane1_74=0x0d4b0c
serdes_preemphasis_lane2_74=0x0d4b0c
serdes_preemphasis_lane3_74=0x0d4b0c
serdes_preemphasis_lane0_87=0x0d4b0c
serdes_preemphasis_lane1_87=0x0d4b0c
serdes_preemphasis_lane2_87=0x0d4b0c
serdes_preemphasis_lane3_87=0x0d4b0c
serdes_preemphasis_lane0_79=0x0d4b0c
serdes_preemphasis_lane1_79=0x0d4b0c
serdes_preemphasis_lane2_79=0x0d4b0c
serdes_preemphasis_lane3_79=0x0d4b0c
serdes_preemphasis_lane0_99=0x0d4b0c
serdes_preemphasis_lane1_99=0x0d4b0c
serdes_preemphasis_lane2_99=0x0d4b0c
serdes_preemphasis_lane3_99=0x0d4b0c
serdes_preemphasis_lane0_95=0x0d4b0c
serdes_preemphasis_lane1_95=0x0d4b0c
serdes_preemphasis_lane2_95=0x0d4b0c
serdes_preemphasis_lane3_95=0x0d4b0c
serdes_preemphasis_lane0_115=0x0d4b0c
serdes_preemphasis_lane1_115=0x0d4b0c
serdes_preemphasis_lane2_115=0x0d4b0c
serdes_preemphasis_lane3_115=0x0d4b0c
serdes_preemphasis_lane0_107=0x0d4b0c
serdes_preemphasis_lane1_107=0x0d4b0c
serdes_preemphasis_lane2_107=0x0d4b0c
serdes_preemphasis_lane3_107=0x0d4b0c
serdes_preemphasis_lane0_123=0x14460a
serdes_preemphasis_lane1_123=0x14460a
serdes_preemphasis_lane2_123=0x14460a
serdes_preemphasis_lane3_123=0x14460a
serdes_preemphasis_lane0_127=0x14460a
serdes_preemphasis_lane1_127=0x14460a
serdes_preemphasis_lane2_127=0x14460a
serdes_preemphasis_lane3_127=0x14460a
reglist_enable=1
scache_filename=/tmp/scache
scache_filename=/var/warmboot/wbscache
schan_intr_enable=0
stable_size=0x5500000
stable_size=0x55000000
stable_location=3
warmboot_knet_shutdown_mode=1
tdma_timeout_usec=3000000
#vxlan flex flow mode
flow_init_mode=1
riot_enable=1
riot_overlay_l3_intf_mem_size=4096
riot_overlay_l3_egress_mem_size=32768
riot_overlay_ecmp_resilient_hash_size=16384
l3_ecmp_levels=2
use_all_splithorizon_groups=1
sai_tunnel_support=1
#This property allows to enable L2 FDB entry to discard based on Source Mac
sai_fdb_entry_l2_discard_src_enable=1
#RDMA
sai_pfc_defaults_disable=1
sai_optimized_mmu=1
#ACL wb count
ctr_evict_enable=0

509
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml Executable file → Normal file
View File

@ -7,116 +7,413 @@
-->
<catalog>
<fans>
<fan id="fan1" >
<property name="present" location="2-0037/fan_present" type="3" bit="0" decode="fanpresent" default="0"/>
<property name="status" location="2-0037/fan_status" type="3" bit="0" decode="fanstatus" default="1"/>
<property name="hw_version" location="3-0053/fan_hw_version" type="0" bit="0"/>
<property name="fan_type" location="3-0053/fan_type"/>
<property name="sn" location="3-0053/fan_sn"/>
<property name="Speed" location="2-0037/hwmon/*/fan1_input"/>
</fan>
<fan id="fan2" >
<property name="present" location="2-0037/fan_present" type="3" bit="1" decode="fanpresent" default="0" />
<property name="status" location="2-0037/fan_status" type="3" bit="1" decode="fanstatus" default="1"/>
<property name="hw_version" location="4-0053/fan_hw_version" type="0" bit="0"/>
<property name="fan_type" location="4-0053/fan_type"/>
<property name="sn" location="4-0053/fan_sn"/>
<property name="Speed" location="2-0037/hwmon/*/fan2_input"/>
</fan>
<fan id="fan3" >
<property name="present" location="2-0037/fan_present" type="3" bit="2" decode="fanpresent" default="0"/>
<property name="status" location="2-0037/fan_status" type="3" bit="2" decode="fanstatus" default="1"/>
<property name="hw_version" location="5-0053/fan_hw_version" type="0" bit="0"/>
<property name="fan_type" location="5-0053/fan_type"/>
<property name="sn" location="5-0053/fan_sn"/>
<property name="Speed" location="2-0037/hwmon/*/fan3_input"/>
</fan>
<fan id="fan4" >
<property name="present" location="2-0037/fan_present" type="3" bit="3" decode="fanpresent" default="0"/>
<property name="status" location="2-0037/fan_status" type="3" bit="3" decode="fanstatus" default="1"/>
<property name="hw_version" location="6-0053/fan_hw_version" type="0" bit="0"/>
<property name="fan_type" location="6-0053/fan_type"/>
<property name="sn" location="6-0053/fan_sn"/>
<property name="Speed" location="2-0037/hwmon/*/fan4_input"/>
</fan>
</fans>
<fan id="fan1" >
<property name="present" location="/sys/wb_plat/fan/fan1/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan1/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan1/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/16-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan1/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan1/motor0/speed"/>
</fan>
<fan id="fan2" >
<property name="present" location="/sys/wb_plat/fan/fan2/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan2/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan2/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/17-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan2/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan2/motor0/speed"/>
</fan>
<fan id="fan3" >
<property name="present" location="/sys/wb_plat/fan/fan3/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan3/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan3/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/18-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan3/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan3/motor0/speed"/>
</fan>
<fan id="fan4" >
<property name="present" location="/sys/wb_plat/fan/fan4/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan4/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan4/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/19-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan4/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan4/motor0/speed"/>
</fan>
</fans>
<temps>
<temp id="air_inlet" >
<property name="temp1_input" location="/2-0048/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/2-0048/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/2-0048/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="air_outlet" >
<property name="temp1_input" location="/2-0049/hwmon/*/temp1_input" type="1" />
<property name="temp1_max" location="/2-0049/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/2-0049/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="air_hotlet" >
<property name="temp1_input" location="/2-004a/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/2-004a/hwmon/*/temp1_max" type="1"/>
<property name="temp1_max_hyst" location="/2-004a/hwmon/*/temp1_max_hyst" type="1"/>
</temp>
</temps>
<psus>
<psu id="psu1" >
<property name="present" location="2-0037/psu_status" type="3" bit="0" decode="psucheck" default="0"/>
<property name="status" location="2-0037/psu_status" type="3" bit="1" decode="psustatus" default="1"/>
<property name="sn" location="7-0050/psu_sn" />
<property name="in_current" location="7-0058/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="7-0058/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="7-0058/hwmon/*/in2_input" type="1" />
<property name="out_current" location="7-0058/hwmon/*/curr2_input" type="1" />
<property name="temp" location="7-0058/hwmon/*/temp1_input" type="1"/>
<property name="hw" location="7-0050/psu_hw" />
<property name="type1" location="7-0050/psu_type" decode="psutype"/>
<property name="fan_speed" location="7-0058/hwmon/*/fan1_input" />
<property name="in_power" location="7-0058/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="7-0058/hwmon/*/power2_input" type="5"/>
</psu>
<psu id="psu2" >
<property name="present" location="2-0037/psu_status" type="3" bit="4" decode="psucheck" default="0"/>
<property name="status" location="2-0037/psu_status" type="3" bit="5" decode="psustatus" default="1"/>
<property name="sn" location="8-0053/psu_sn" />
<property name="in_current" location="8-005b/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="8-005b/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="8-005b/hwmon/*/in2_input" type="1" />
<property name="out_current" location="8-005b/hwmon/*/curr2_input" type="1" />
<property name="temp" location="8-005b/hwmon/*/temp1_input" type="1"/>
<property name="hw" location="8-0053/psu_hw" />
<property name="type1" location="8-0053/psu_type" decode="psutype"/>
<property name="fan_speed" location="8-005b/hwmon/*/fan1_input" />
<property name="in_power" location="8-005b/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="8-005b/hwmon/*/power2_input" type="5"/>
</psu>
<temp id="INLET_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_input" type="1" addend="-3"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="OUTLET_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="MAC_IN_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_input" type="1" />
<property name="temp1_max" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="MAC_OUT_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_max" type="1"/>
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_max_hyst" type="1"/>
</temp>
</temps>
<psus>
<psu id="psu1" >
<property name="present" location="/sys/wb_plat/psu/psu1/present" type="4" decode="psucheck" default="1"/>
<property name="status" location="/sys/wb_plat/psu/psu1/output" type="4" decode="psustatus" default="1"/>
<property name="psu" e2type="fru" location="/sys/bus/i2c/devices/24-0050/eeprom"/>
<property name="in_current" location="/sys/bus/i2c/devices/24-0058/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="/sys/bus/i2c/devices/24-0058/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="/sys/bus/i2c/devices/24-0058/hwmon/*/in2_input" type="1" />
<property name="out_current" location="/sys/bus/i2c/devices/24-0058/hwmon/*/curr2_input" type="1" />
<property name="temp" location="/sys/bus/i2c/devices/24-0058/hwmon/*/temp1_input" type="1"/>
<property name="fan_speed" location="/sys/bus/i2c/devices/24-0058/hwmon/*/fan1_input" />
<property name="in_power" location="/sys/bus/i2c/devices/24-0058/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="/sys/bus/i2c/devices/24-0058/hwmon/*/power2_input" type="5"/>
</psu>
<psu id="psu2" >
<property name="present" location="/sys/wb_plat/psu/psu2/present" type="4" decode="psucheck" default="1"/>
<property name="status" location="/sys/wb_plat/psu/psu2/output" type="4" decode="psustatus" default="1"/>
<property name="psu" e2type="fru" location="/sys/bus/i2c/devices/25-0050/eeprom"/>
<property name="in_current" location="/sys/bus/i2c/devices/25-0058/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="/sys/bus/i2c/devices/25-0058/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="/sys/bus/i2c/devices/25-0058/hwmon/*/in2_input" type="1" />
<property name="out_current" location="/sys/bus/i2c/devices/25-0058/hwmon/*/curr2_input" type="1" />
<property name="temp" location="/sys/bus/i2c/devices/25-0058/hwmon/*/temp1_input" type="1"/>
<property name="fan_speed" location="/sys/bus/i2c/devices/25-0058/hwmon/*/fan1_input" />
<property name="in_power" location="/sys/bus/i2c/devices/25-0058/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="/sys/bus/i2c/devices/25-0058/hwmon/*/power2_input" type="5"/>
</psu>
</psus>
<dcdcs>
<dcdc id="Switch_ZSFP1_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="22.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_QSFP1_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="22.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_5v0_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_ZSFP1_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_QSFP1_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_5v0_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="6.000" />
<property name="dcdc_min" gettype="config" value="4.000" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_Cpld_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_Cpld_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.300" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.800" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_SSD_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="4.500" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_SSD_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="4.686" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_5v_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v7_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_5v_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="6.000" />
<property name="dcdc_min" gettype="config" value="4.000" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v7_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.040" />
<property name="dcdc_min" gettype="config" value="1.360" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_CORE_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="47.300" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v05_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="15.400" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_CORE_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.184" />
<property name="dcdc_min" gettype="config" value="1.456" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v05_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.260" />
<property name="dcdc_min" gettype="config" value="0.840" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_CORE_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="220.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_ANALOG_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="18.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_CORE_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.200" />
<property name="dcdc_min" gettype="config" value="0.600" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_ANALOG_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="0.960" />
<property name="dcdc_min" gettype="config" value="0.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="9.900" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_2v23_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_2v23_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.676" />
<property name="dcdc_min" gettype="config" value="1.784" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
</dcdcs>
<mactemps>
<mactemp id="MAC_DIE_0" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp1_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_1" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp2_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_2" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp3_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_3" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp4_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_4" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp5_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_5" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp6_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_6" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp7_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_7" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp8_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_8" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp9_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_9" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp10_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_10" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp11_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_11" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp12_input" type="1"/>
</mactemp>
</mactemps>
<cpus location="/sys/class/hwmon/hwmon0"/>
<ports_rx>
<mgmt_rx id="mgmt" sender="eth0" >
<property name="mgmt" location="/eth0/statistics/rx_packets" type="4"/>
</mgmt_rx>
</ports_rx>
<decode>
<fanpresent>
<code key="1" value="ABSENT"/>
<code key="0" value="PRESENT"/>
</fanpresent>
<fanstatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</fanstatus>
<psucheck>
<code key="1" value="ABSENT"/>
<code key="0" value="PRESENT"/>
</psucheck>
<psustatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</psustatus>
<psutype>
<code key="CSU550AP-3-300" value="RG-PA550I-F"/>
<code key="DPS-550AB-39 A" value="RG-PA550I-F"/>
</psutype>
<fanpresent>
<code key="1" value="PRESENT"/>
<code key="0" value="ABSENT"/>
</fanpresent>
<fanstatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</fanstatus>
<psucheck>
<code key="1" value="PRESENT"/>
<code key="0" value="ABSENT"/>
</psucheck>
<psustatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</psustatus>
<psutype>
<code key="CSU550AP-3-500" value="PA550II-F"/>
<code key="DPS-550AB-39 A" value="PA550II-F"/>
<code key="GW-CRPS550N2C" value="PA550II-F"/>
<code key="CSU550AP-3-300" value="PA550II-F"/>
<code key="DPS-550AB-39 B" value="PA550II-F"/>
<code key="CSU550AP-3" value="PA550II-F"/>
<code key="CSU550AP-3-501" value="PA550II-R"/>
<code key="DPS-550AB-40 A" value="PA550II-R"/>
<code key="GW-CRPS550N2RC" value="PA550II-R"/>
</psutype>
<fan_display_name>
<code key="M1HFAN I-F" value="M1HFAN I-F"/>
<code key="M1HFAN I-R" value="M1HFAN I-R"/>
</fan_display_name>
</decode>
</catalog>

View File

@ -0,0 +1,419 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
### type 1 result/1000
type 2 result/100
type 3 read bit
### property need check must add int front
-->
<catalog>
<fans>
<fan id="fan1" >
<property name="present" location="/sys/wb_plat/fan/fan1/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan1/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan1/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/16-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan1/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan1/motor0/speed"/>
</fan>
<fan id="fan2" >
<property name="present" location="/sys/wb_plat/fan/fan2/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan2/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan2/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/17-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan2/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan2/motor0/speed"/>
</fan>
<fan id="fan3" >
<property name="present" location="/sys/wb_plat/fan/fan3/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan3/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan3/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/18-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan3/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan3/motor0/speed"/>
</fan>
<fan id="fan4" >
<property name="present" location="/sys/wb_plat/fan/fan4/present" type="4" decode="fanpresent" default="1"/>
<property name="status" location="/sys/wb_plat/fan/fan4/motor0/status" type="4" decode="fanstatus" default="1"/>
<property name="status2" location="/sys/wb_plat/fan/fan4/motor1/status" type="4" decode="fanstatus" default="1"/>
<property name="fru" e2type="fru" location="/sys/bus/i2c/devices/19-0050/eeprom"/>
<property name="rotor1_speed" location="/sys/wb_plat/fan/fan4/motor1/speed"/>
<property name="rotor2_speed" location="/sys/wb_plat/fan/fan4/motor0/speed"/>
</fan>
</fans>
<temps>
<temp id="INLET_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_input" type="1" addend="-3"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-004c/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="OUTLET_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-0048/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="MAC_IN_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_input" type="1" />
<property name="temp1_max" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_max" type="1" />
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-004a/hwmon/*/temp1_max_hyst" type="1" />
</temp>
<temp id="MAC_OUT_TEMP" >
<property name="temp1_input" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_input" type="1"/>
<property name="temp1_max" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_max" type="1"/>
<property name="temp1_max_hyst" location="/sys/bus/i2c/devices/3-0049/hwmon/*/temp1_max_hyst" type="1"/>
</temp>
</temps>
<psus>
<psu id="psu1" >
<property name="present" location="/sys/wb_plat/psu/psu1/present" type="4" decode="psucheck" default="1"/>
<property name="status" location="/sys/wb_plat/psu/psu1/output" type="4" decode="psustatus" default="1"/>
<property name="psu" e2type="fru" location="/sys/bus/i2c/devices/24-0050/eeprom"/>
<property name="in_current" location="/sys/bus/i2c/devices/24-0058/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="/sys/bus/i2c/devices/24-0058/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="/sys/bus/i2c/devices/24-0058/hwmon/*/in2_input" type="1" />
<property name="out_current" location="/sys/bus/i2c/devices/24-0058/hwmon/*/curr2_input" type="1" />
<property name="temp" location="/sys/bus/i2c/devices/24-0058/hwmon/*/temp1_input" type="1"/>
<property name="fan_speed" location="/sys/bus/i2c/devices/24-0058/hwmon/*/fan1_input" />
<property name="in_power" location="/sys/bus/i2c/devices/24-0058/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="/sys/bus/i2c/devices/24-0058/hwmon/*/power2_input" type="5"/>
</psu>
<psu id="psu2" >
<property name="present" location="/sys/wb_plat/psu/psu2/present" type="4" decode="psucheck" default="1"/>
<property name="status" location="/sys/wb_plat/psu/psu2/output" type="4" decode="psustatus" default="1"/>
<property name="psu" e2type="fru" location="/sys/bus/i2c/devices/25-0050/eeprom"/>
<property name="in_current" location="/sys/bus/i2c/devices/25-0058/hwmon/*/curr1_input" type="1" />
<property name="in_voltage" location="/sys/bus/i2c/devices/25-0058/hwmon/*/in1_input" type="1"/>
<property name="out_voltage" location="/sys/bus/i2c/devices/25-0058/hwmon/*/in2_input" type="1" />
<property name="out_current" location="/sys/bus/i2c/devices/25-0058/hwmon/*/curr2_input" type="1" />
<property name="temp" location="/sys/bus/i2c/devices/25-0058/hwmon/*/temp1_input" type="1"/>
<property name="fan_speed" location="/sys/bus/i2c/devices/25-0058/hwmon/*/fan1_input" />
<property name="in_power" location="/sys/bus/i2c/devices/25-0058/hwmon/*/power1_input" type="5"/>
<property name="out_power" location="/sys/bus/i2c/devices/25-0058/hwmon/*/power2_input" type="5"/>
</psu>
</psus>
<dcdcs>
<dcdc id="Switch_ZSFP1_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="22.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_QSFP1_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="22.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_5v0_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_ZSFP1_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_QSFP1_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_5v0_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0040/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="6.000" />
<property name="dcdc_min" gettype="config" value="4.000" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_Cpld_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_Cpld_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0041/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.300" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.800" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_SSD_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="4.500" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Con_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Con_SSD_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0042/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_3v3_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="4.686" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_5v_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v7_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_3v3_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in1_input" type="6" />
<property name="dcdc_max" gettype="config" value="3.960" />
<property name="dcdc_min" gettype="config" value="2.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_5v_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="6.000" />
<property name="dcdc_min" gettype="config" value="4.000" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v7_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0043/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.040" />
<property name="dcdc_min" gettype="config" value="1.360" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_CORE_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="47.300" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v05_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="15.400" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_CORE_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.184" />
<property name="dcdc_min" gettype="config" value="1.456" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v05_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0060/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.260" />
<property name="dcdc_min" gettype="config" value="0.840" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_CORE_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="220.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_ANALOG_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/curr3_input" type="6" />
<property name="dcdc_max" gettype="config" value="18.000" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Switch_CORE_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.200" />
<property name="dcdc_min" gettype="config" value="0.600" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Switch_ANALOG_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-0064/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="0.960" />
<property name="dcdc_min" gettype="config" value="0.640" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_1v2_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/curr1_input" type="6" />
<property name="dcdc_max" gettype="config" value="9.900" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_2v23_C" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/curr2_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.200" />
<property name="dcdc_min" gettype="config" value="-1.000" />
<property name="dcdc_unit" gettype="config" value="A" />
</dcdc>
<dcdc id="Cpu_1v2_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/in2_input" type="6" />
<property name="dcdc_max" gettype="config" value="1.440" />
<property name="dcdc_min" gettype="config" value="0.960" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
<dcdc id="Cpu_2v23_V" >
<property name="dcdc_input" location="/sys/bus/i2c/devices/7-006c/hwmon/hwmon*/in3_input" type="6" />
<property name="dcdc_max" gettype="config" value="2.676" />
<property name="dcdc_min" gettype="config" value="1.784" />
<property name="dcdc_unit" gettype="config" value="V" />
</dcdc>
</dcdcs>
<mactemps>
<mactemp id="MAC_DIE_0" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp1_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_1" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp2_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_2" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp3_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_3" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp4_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_4" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp5_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_5" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp6_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_6" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp7_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_7" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp8_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_8" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp9_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_9" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp10_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_10" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp11_input" type="1"/>
</mactemp>
<mactemp id="MAC_DIE_11" >
<property name="temp_input" location="/sys/bus/i2c/devices/3-0044/hwmon/hwmon*/temp12_input" type="1"/>
</mactemp>
</mactemps>
<cpus location="/sys/class/hwmon/hwmon0"/>
<decode>
<fanpresent>
<code key="1" value="PRESENT"/>
<code key="0" value="ABSENT"/>
</fanpresent>
<fanstatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</fanstatus>
<psucheck>
<code key="1" value="PRESENT"/>
<code key="0" value="ABSENT"/>
</psucheck>
<psustatus>
<code key="1" value="OK"/>
<code key="0" value="NOT OK"/>
</psustatus>
<psutype>
<code key="CSU550AP-3-500" value="PA550II-F"/>
<code key="DPS-550AB-39 A" value="PA550II-F"/>
<code key="GW-CRPS550N2C" value="PA550II-F"/>
<code key="CSU550AP-3-300" value="PA550II-F"/>
<code key="DPS-550AB-39 B" value="PA550II-F"/>
<code key="CSU550AP-3" value="PA550II-F"/>
<code key="CSU550AP-3-501" value="PA550II-R"/>
<code key="DPS-550AB-40 A" value="PA550II-R"/>
<code key="GW-CRPS550N2RC" value="PA550II-R"/>
</psutype>
<fan_display_name>
<code key="M1HFAN I-F" value="M1HFAN I-F"/>
<code key="M1HFAN I-R" value="M1HFAN I-R"/>
</fan_display_name>
</decode>
</catalog>

View File

@ -0,0 +1,961 @@
#!/usr/bin/python3
import collections
from datetime import datetime, timedelta
from bitarray import bitarray
__DEBUG__ = "N"
class FruException(Exception):
def __init__(self, message='fruerror', code=-100):
err = 'errcode: {0} message:{1}'.format(code, message)
Exception.__init__(self, err)
self.code = code
self.message = message
def e_print(err):
print("ERROR: " + err)
def d_print(debug_info):
if __DEBUG__ == "Y":
print(debug_info)
class FruUtil():
@staticmethod
def decodeLength(value):
a = bitarray(8)
a.setall(True)
a[0:1] = 0
a[1:2] = 0
x = ord(a.tobytes())
return x & ord(value)
@staticmethod
def minToData():
starttime = datetime(1996, 1, 1, 0, 0, 0)
endtime = datetime.now()
seconds = (endtime - starttime).total_seconds()
mins = seconds // 60
m = int(round(mins))
return m
@staticmethod
def getTimeFormat():
return datetime.now().strftime('%Y-%m-%d')
@staticmethod
def getTypeLength(value):
if value is None or len(value) == 0:
return 0
a = bitarray(8)
a.setall(False)
a[0:1] = 1
a[1:2] = 1
x = ord(a.tobytes())
return x | len(value)
@staticmethod
def checksum(b):
result = 0
for item in b:
result += ord(item)
return (0x100 - (result & 0xff)) & 0xff
class BaseArea(object):
SUGGESTED_SIZE_COMMON_HEADER = 8
SUGGESTED_SIZE_INTERNAL_USE_AREA = 72
SUGGESTED_SIZE_CHASSIS_INFO_AREA = 32
SUGGESTED_SIZE_BOARD_INFO_AREA = 80
SUGGESTED_SIZE_PRODUCT_INFO_AREA = 80
INITVALUE = b'\x00'
resultvalue = INITVALUE * 256
COMMON_HEAD_VERSION = b'\x01'
__childList = None
def __init__(self, name="", size=0, offset=0):
self.__childList = []
self._offset = offset
self.name = name
self._size = size
self._isPresent = False
self._data = b'\x00' * size
@property
def childList(self):
return self.__childList
@childList.setter
def childList(self, value):
self.__childList = value
@property
def offset(self):
return self._offset
@offset.setter
def offset(self, value):
self._offset = value
@property
def size(self):
return self._size
@size.setter
def size(self, value):
self._size = value
@property
def data(self):
return self._data
@data.setter
def data(self, value):
self._data = value
@property
def isPresent(self):
return self._isPresent
@isPresent.setter
def isPresent(self, value):
self._isPresent = value
class InternalUseArea(BaseArea):
pass
class ChassisInfoArea(BaseArea):
pass
class BoardInfoArea(BaseArea):
_boardTime = None
_fields = None
_mfg_date = None
areaversion = None
_boardversion = None
_language = None
def __str__(self):
formatstr = "version : %x\n" \
"length : %d \n" \
"language : %x \n" \
"mfg_date : %s \n" \
"boardManufacturer : %s \n" \
"boardProductName : %s \n" \
"boardSerialNumber : %s \n" \
"boardPartNumber : %s \n" \
"fruFileId : %s \n"
tmpstr = formatstr % (ord(self.boardversion), self.size,
self.language, self.getMfgRealData(),
self.boardManufacturer, self.boardProductName,
self.boardSerialNumber, self.boardPartNumber,
self.fruFileId)
for i in range(1, 11):
valtmp = "boardextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
tmpstr += "boardextra%d : %s \n" % (i, valtmpval)
else:
break
return tmpstr
def todict(self):
dic = collections.OrderedDict()
dic["boardversion"] = ord(self.boardversion)
dic["boardlength"] = self.size
dic["boardlanguage"] = self.language
dic["boardmfg_date"] = self.getMfgRealData()
dic["boardManufacturer"] = self.boardManufacturer
dic["boardProductName"] = self.boardProductName
dic["boardSerialNumber"] = self.boardSerialNumber
dic["boardPartNumber"] = self.boardPartNumber
dic["boardfruFileId"] = self.fruFileId
for i in range(1, 11):
valtmp = "boardextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
dic[valtmp] = valtmpval
else:
break
return dic
def decodedata(self):
index = 0
self.areaversion = self.data[index]
index += 1
d_print("decode length :%d class size:%d" %
((ord(self.data[index]) * 8), self.size))
index += 2
timetmp = self.data[index: index + 3]
self.mfg_date = ord(timetmp[0]) | (
ord(timetmp[1]) << 8) | (ord(timetmp[2]) << 16)
d_print("decode getMfgRealData :%s" % self.getMfgRealData())
index += 3
templen = FruUtil.decodeLength(self.data[index])
self.boardManufacturer = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode boardManufacturer:%s" % self.boardManufacturer)
templen = FruUtil.decodeLength(self.data[index])
self.boardProductName = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode boardProductName:%s" % self.boardProductName)
templen = FruUtil.decodeLength(self.data[index])
self.boardSerialNumber = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode boardSerialNumber:%s" % self.boardSerialNumber)
templen = FruUtil.decodeLength(self.data[index])
self.boardPartNumber = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode boardPartNumber:%s" % self.boardPartNumber)
templen = FruUtil.decodeLength(self.data[index])
self.fruFileId = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode fruFileId:%s" % self.fruFileId)
for i in range(1, 11):
valtmp = "boardextra%d" % i
if self.data[index] != chr(0xc1):
templen = FruUtil.decodeLength(self.data[index])
tmpval = self.data[index + 1: index + templen + 1]
setattr(self, valtmp, tmpval)
index += templen + 1
d_print("decode boardextra%d:%s" % (i, tmpval))
else:
break
def fruSetValue(self, field, value):
tmp_field = getattr(self, field, None)
if tmp_field is not None:
setattr(self, field, value)
def recalcute(self):
d_print("boardInfoArea version:%x" % ord(self.boardversion))
d_print("boardInfoArea length:%d" % self.size)
d_print("boardInfoArea language:%x" % self.language)
self.mfg_date = FruUtil.minToData()
d_print("boardInfoArea mfg_date:%x" % self.mfg_date)
self.data = chr(ord(self.boardversion)) + \
chr(self.size // 8) + chr(self.language)
self.data += chr(self.mfg_date & 0xFF)
self.data += chr((self.mfg_date >> 8) & 0xFF)
self.data += chr((self.mfg_date >> 16) & 0xFF)
d_print("boardInfoArea boardManufacturer:%s" % self.boardManufacturer)
typelength = FruUtil.getTypeLength(self.boardManufacturer)
self.data += chr(typelength)
self.data += self.boardManufacturer
d_print("boardInfoArea boardProductName:%s" % self.boardProductName)
self.data += chr(FruUtil.getTypeLength(self.boardProductName))
self.data += self.boardProductName
d_print("boardInfoArea boardSerialNumber:%s" % self.boardSerialNumber)
self.data += chr(FruUtil.getTypeLength(self.boardSerialNumber))
self.data += self.boardSerialNumber
d_print("boardInfoArea boardPartNumber:%s" % self.boardPartNumber)
self.data += chr(FruUtil.getTypeLength(self.boardPartNumber))
self.data += self.boardPartNumber
d_print("boardInfoArea fruFileId:%s" % self.fruFileId)
self.data += chr(FruUtil.getTypeLength(self.fruFileId))
self.data += self.fruFileId
for i in range(1, 11):
valtmp = "boardextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
d_print("boardInfoArea boardextra%d:%s" % (i, valtmpval))
self.data += chr(FruUtil.getTypeLength(valtmpval))
if valtmpval is not None:
self.data += valtmpval
else:
break
self.data += chr(0xc1)
if len(self.data) > (self.size - 1):
incr = (len(self.data) - self.size) // 8 + 1
self.size += incr * 8
self.data = self.data[0:1] + chr(self.size // 8) + self.data[2:]
d_print("self data:%d" % len(self.data))
d_print("self size:%d" % self.size)
d_print("adjust size:%d" % (self.size - len(self.data) - 1))
self.data = self.data.ljust((self.size - 1), chr(self.INITVALUE[0]))
# checksum
checksum = FruUtil.checksum(self.data)
d_print("board info checksum:%x" % checksum)
self.data += chr(checksum)
def getMfgRealData(self):
starttime = datetime(1996, 1, 1, 0, 0, 0)
mactime = starttime + timedelta(minutes=self.mfg_date)
return mactime
@property
def language(self):
self._language = 25
return self._language
@property
def mfg_date(self):
return self._mfg_date
@mfg_date.setter
def mfg_date(self, val):
self._mfg_date = val
@property
def boardversion(self):
self._boardversion = self.COMMON_HEAD_VERSION
return self._boardversion
@property
def fruFileId(self):
return self._FRUFileID
@fruFileId.setter
def fruFileId(self, val):
self._FRUFileID = val
@property
def boardPartNumber(self):
return self._boardPartNumber
@boardPartNumber.setter
def boardPartNumber(self, val):
self._boardPartNumber = val
@property
def boardSerialNumber(self):
return self._boardSerialNumber
@boardSerialNumber.setter
def boardSerialNumber(self, val):
self._boardSerialNumber = val
@property
def boardProductName(self):
return self._boradProductName
@boardProductName.setter
def boardProductName(self, val):
self._boradProductName = val
@property
def boardManufacturer(self):
return self._boardManufacturer
@boardManufacturer.setter
def boardManufacturer(self, val):
self._boardManufacturer = val
@property
def boardTime(self):
return self._boardTime
@boardTime.setter
def boardTime(self, val):
self._boardTime = val
@property
def fields(self):
return self._fields
@fields.setter
def fields(self, val):
self._fields = val
class ProductInfoArea(BaseArea):
_productManufacturer = None
_productAssetTag = None
_FRUFileID = None
_language = None
def __str__(self):
formatstr = "version : %x\n" \
"length : %d \n" \
"language : %x \n" \
"productManufacturer : %s \n" \
"productName : %s \n" \
"productPartModelName: %s \n" \
"productVersion : %s \n" \
"productSerialNumber : %s \n" \
"productAssetTag : %s \n" \
"fruFileId : %s \n"
tmpstr = formatstr % (ord(self.areaversion), self.size,
self.language, self.productManufacturer,
self.productName, self.productPartModelName,
self.productVersion, self.productSerialNumber,
self.productAssetTag, self.fruFileId)
for i in range(1, 11):
valtmp = "productextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
tmpstr += "productextra%d : %s \n" % (i, valtmpval)
else:
break
return tmpstr
def todict(self):
dic = collections.OrderedDict()
dic["productversion"] = ord(self.areaversion)
dic["productlength"] = self.size
dic["productlanguage"] = self.language
dic["productManufacturer"] = self.productManufacturer
dic["productName"] = self.productName
dic["productPartModelName"] = self.productPartModelName
dic["productVersion"] = int(self.productVersion, 16)
dic["productSerialNumber"] = self.productSerialNumber
dic["productAssetTag"] = self.productAssetTag
dic["productfruFileId"] = self.fruFileId
for i in range(1, 11):
valtmp = "productextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
dic[valtmp] = valtmpval
else:
break
return dic
def decodedata(self):
index = 0
self.areaversion = self.data[index] # 0
index += 1
d_print("decode length %d" % (ord(self.data[index]) * 8))
d_print("class size %d" % self.size)
index += 2
templen = FruUtil.decodeLength(self.data[index])
self.productManufacturer = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productManufacturer:%s" % self.productManufacturer)
templen = FruUtil.decodeLength(self.data[index])
self.productName = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productName:%s" % self.productName)
templen = FruUtil.decodeLength(self.data[index])
self.productPartModelName = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productPartModelName:%s" % self.productPartModelName)
templen = FruUtil.decodeLength(self.data[index])
self.productVersion = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productVersion:%s" % self.productVersion)
templen = FruUtil.decodeLength(self.data[index])
self.productSerialNumber = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productSerialNumber:%s" % self.productSerialNumber)
templen = FruUtil.decodeLength(self.data[index])
self.productAssetTag = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode productAssetTag:%s" % self.productAssetTag)
templen = FruUtil.decodeLength(self.data[index])
self.fruFileId = self.data[index + 1: index + templen + 1]
index += templen + 1
d_print("decode fruFileId:%s" % self.fruFileId)
for i in range(1, 11):
valtmp = "productextra%d" % i
if self.data[index] != chr(0xc1) and index < self.size - 1:
templen = FruUtil.decodeLength(self.data[index])
if templen == 0:
break
tmpval = self.data[index + 1: index + templen + 1]
d_print("decode boardextra%d:%s" % (i, tmpval))
setattr(self, valtmp, tmpval)
index += templen + 1
else:
break
@property
def productVersion(self):
return self._productVersion
@productVersion.setter
def productVersion(self, name):
self._productVersion = name
@property
def areaversion(self):
self._areaversion = self.COMMON_HEAD_VERSION
return self._areaversion
@areaversion.setter
def areaversion(self, name):
self._areaversion = name
@property
def language(self):
self._language = 25
return self._language
@property
def productManufacturer(self):
return self._productManufacturer
@productManufacturer.setter
def productManufacturer(self, name):
self._productManufacturer = name
@property
def productName(self):
return self._productName
@productName.setter
def productName(self, name):
self._productName = name
@property
def productPartModelName(self):
return self._productPartModelName
@productPartModelName.setter
def productPartModelName(self, name):
self._productPartModelName = name
@property
def productSerialNumber(self):
return self._productSerialNumber
@productSerialNumber.setter
def productSerialNumber(self, name):
self._productSerialNumber = name
@property
def productAssetTag(self):
return self._productAssetTag
@productAssetTag.setter
def productAssetTag(self, name):
self._productAssetTag = name
@property
def fruFileId(self):
return self._FRUFileID
@fruFileId.setter
def fruFileId(self, name):
self._FRUFileID = name
def fruSetValue(self, field, value):
tmp_field = getattr(self, field, None)
if tmp_field is not None:
setattr(self, field, value)
def recalcute(self):
d_print("product version:%x" % ord(self.areaversion))
d_print("product length:%d" % self.size)
d_print("product language:%x" % self.language)
self.data = chr(ord(self.areaversion)) + \
chr(self.size // 8) + chr(self.language)
typelength = FruUtil.getTypeLength(self.productManufacturer)
self.data += chr(typelength)
self.data += self.productManufacturer
self.data += chr(FruUtil.getTypeLength(self.productName))
self.data += self.productName
self.data += chr(FruUtil.getTypeLength(self.productPartModelName))
self.data += self.productPartModelName
self.data += chr(FruUtil.getTypeLength(self.productVersion))
self.data += self.productVersion
self.data += chr(FruUtil.getTypeLength(self.productSerialNumber))
self.data += self.productSerialNumber
self.data += chr(FruUtil.getTypeLength(self.productAssetTag))
if self.productAssetTag is not None:
self.data += self.productAssetTag
self.data += chr(FruUtil.getTypeLength(self.fruFileId))
self.data += self.fruFileId
for i in range(1, 11):
valtmp = "productextra%d" % i
if hasattr(self, valtmp):
valtmpval = getattr(self, valtmp)
d_print("boardInfoArea productextra%d:%s" % (i, valtmpval))
self.data += chr(FruUtil.getTypeLength(valtmpval))
if valtmpval is not None:
self.data += valtmpval
else:
break
self.data += chr(0xc1)
if len(self.data) > (self.size - 1):
incr = (len(self.data) - self.size) // 8 + 1
self.size += incr * 8
d_print("self.data:%d" % len(self.data))
d_print("self.size:%d" % self.size)
self.data = self.data[0:1] + chr(self.size // 8) + self.data[2:]
self.data = self.data.ljust((self.size - 1), chr(self.INITVALUE[0]))
checksum = FruUtil.checksum(self.data)
d_print("board info checksum:%x" % checksum)
self.data += chr(checksum)
class MultiRecordArea(BaseArea):
pass
class Field(object):
def __init__(self, fieldType="ASCII", fieldData=""):
self.fieldData = fieldData
self.fieldType = fieldType
@property
def fieldType(self):
return self.fieldType
@property
def fieldData(self):
return self.fieldData
class ipmifru(BaseArea):
_BoardInfoArea = None
_ProductInfoArea = None
_InternalUseArea = None
_ChassisInfoArea = None
_multiRecordArea = None
_productinfoAreaOffset = BaseArea.INITVALUE
_boardInfoAreaOffset = BaseArea.INITVALUE
_internalUserAreaOffset = BaseArea.INITVALUE
_chassicInfoAreaOffset = BaseArea.INITVALUE
_multiRecordAreaOffset = BaseArea.INITVALUE
_bindata = None
_bodybin = None
_version = BaseArea.COMMON_HEAD_VERSION
_zeroCheckSum = None
_frusize = 256
def __str__(self):
tmpstr = ""
if self.boardInfoArea.isPresent:
tmpstr += "\nboardinfoarea: \n"
tmpstr += self.boardInfoArea.__str__()
if self.productInfoArea.isPresent:
tmpstr += "\nproductinfoarea: \n"
tmpstr += self.productInfoArea.__str__()
return tmpstr
def decodeBin(self, eeprom):
commonHead = eeprom[0:8]
d_print("decode version %x" % ord(commonHead[0]))
if ord(self.COMMON_HEAD_VERSION) != ord(commonHead[0]):
raise FruException("HEAD VERSION error,not Fru format!", -10)
if FruUtil.checksum(commonHead[0:7]) != ord(commonHead[7]):
strtemp = "check header checksum error [cal:%02x data:%02x]" % (
FruUtil.checksum(commonHead[0:7]), ord(commonHead[7]))
raise FruException(strtemp, -3)
if ord(commonHead[1]) != ord(self.INITVALUE):
d_print("Internal Use Area is present")
self.internalUseArea = InternalUseArea(
name="Internal Use Area", size=self.SUGGESTED_SIZE_INTERNAL_USE_AREA)
self.internalUseArea.isPresent = True
self.internalUserAreaOffset = ord(commonHead[1])
self.internalUseArea.data = eeprom[self.internalUserAreaOffset * 8: (
self.internalUserAreaOffset * 8 + self.internalUseArea.size)]
if ord(commonHead[2]) != ord(self.INITVALUE):
d_print("Chassis Info Area is present")
self.chassisInfoArea = ChassisInfoArea(
name="Chassis Info Area", size=self.SUGGESTED_SIZE_CHASSIS_INFO_AREA)
self.chassisInfoArea.isPresent = True
self.chassicInfoAreaOffset = ord(commonHead[2])
self.chassisInfoArea.data = eeprom[self.chassicInfoAreaOffset * 8: (
self.chassicInfoAreaOffset * 8 + self.chassisInfoArea.size)]
if ord(commonHead[3]) != ord(self.INITVALUE):
self.boardInfoArea = BoardInfoArea(
name="Board Info Area", size=self.SUGGESTED_SIZE_BOARD_INFO_AREA)
self.boardInfoArea.isPresent = True
self.boardInfoAreaOffset = ord(commonHead[3])
self.boardInfoArea.size = ord(
eeprom[self.boardInfoAreaOffset * 8 + 1]) * 8
d_print("Board Info Area is present size:%d" %
(self.boardInfoArea.size))
self.boardInfoArea.data = eeprom[self.boardInfoAreaOffset * 8: (
self.boardInfoAreaOffset * 8 + self.boardInfoArea.size)]
if FruUtil.checksum(self.boardInfoArea.data[:-1]) != ord(self.boardInfoArea.data[-1:]):
strtmp = "check boardInfoArea checksum error[cal:%02x data:%02x]" % \
(FruUtil.checksum(
self.boardInfoArea.data[:-1]), ord(self.boardInfoArea.data[-1:]))
raise FruException(strtmp, -3)
self.boardInfoArea.decodedata()
if ord(commonHead[4]) != ord(self.INITVALUE):
d_print("Product Info Area is present")
self.productInfoArea = ProductInfoArea(
name="Product Info Area ", size=self.SUGGESTED_SIZE_PRODUCT_INFO_AREA)
self.productInfoArea.isPresent = True
self.productinfoAreaOffset = ord(commonHead[4])
d_print("length offset value: %02x" %
ord(eeprom[self.productinfoAreaOffset * 8 + 1]))
self.productInfoArea.size = ord(
eeprom[self.productinfoAreaOffset * 8 + 1]) * 8
d_print("Product Info Area is present size:%d" %
(self.productInfoArea.size))
self.productInfoArea.data = eeprom[self.productinfoAreaOffset * 8: (
self.productinfoAreaOffset * 8 + self.productInfoArea.size)]
if FruUtil.checksum(self.productInfoArea.data[:-1]) != ord(self.productInfoArea.data[-1:]):
strtmp = "check productInfoArea checksum error [cal:%02x data:%02x]" % (
FruUtil.checksum(self.productInfoArea.data[:-1]), ord(self.productInfoArea.data[-1:]))
raise FruException(strtmp, -3)
self.productInfoArea.decodedata()
if ord(commonHead[5]) != ord(self.INITVALUE):
self.multiRecordArea = MultiRecordArea(
name="MultiRecord record Area ")
d_print("MultiRecord record present")
self.multiRecordArea.isPresent = True
self.multiRecordAreaOffset = ord(commonHead[5])
self.multiRecordArea.data = eeprom[self.multiRecordAreaOffset * 8: (
self.multiRecordAreaOffset * 8 + self.multiRecordArea.size)]
def initDefault(self):
self.version = self.COMMON_HEAD_VERSION
self.internalUserAreaOffset = self.INITVALUE
self.chassicInfoAreaOffset = self.INITVALUE
self.boardInfoAreaOffset = self.INITVALUE
self.productinfoAreaOffset = self.INITVALUE
self.multiRecordAreaOffset = self.INITVALUE
self.zeroCheckSum = self.INITVALUE
self.offset = self.SUGGESTED_SIZE_COMMON_HEADER
self.productInfoArea = None
self.internalUseArea = None
self.boardInfoArea = None
self.chassisInfoArea = None
self.multiRecordArea = None
# self.recalcute()
@property
def version(self):
return self._version
@version.setter
def version(self, name):
self._version = name
@property
def internalUserAreaOffset(self):
return self._internalUserAreaOffset
@internalUserAreaOffset.setter
def internalUserAreaOffset(self, obj):
self._internalUserAreaOffset = obj
@property
def chassicInfoAreaOffset(self):
return self._chassicInfoAreaOffset
@chassicInfoAreaOffset.setter
def chassicInfoAreaOffset(self, obj):
self._chassicInfoAreaOffset = obj
@property
def productinfoAreaOffset(self):
return self._productinfoAreaOffset
@productinfoAreaOffset.setter
def productinfoAreaOffset(self, obj):
self._productinfoAreaOffset = obj
@property
def boardInfoAreaOffset(self):
return self._boardInfoAreaOffset
@boardInfoAreaOffset.setter
def boardInfoAreaOffset(self, obj):
self._boardInfoAreaOffset = obj
@property
def multiRecordAreaOffset(self):
return self._multiRecordAreaOffset
@multiRecordAreaOffset.setter
def multiRecordAreaOffset(self, obj):
self._multiRecordAreaOffset = obj
@property
def zeroCheckSum(self):
return self._zeroCheckSum
@zeroCheckSum.setter
def zeroCheckSum(self, obj):
self._zeroCheckSum = obj
@property
def productInfoArea(self):
return self._ProductInfoArea
@productInfoArea.setter
def productInfoArea(self, obj):
self._ProductInfoArea = obj
@property
def internalUseArea(self):
return self._InternalUseArea
@internalUseArea.setter
def internalUseArea(self, obj):
self.internalUseArea = obj
@property
def boardInfoArea(self):
return self._BoardInfoArea
@boardInfoArea.setter
def boardInfoArea(self, obj):
self._BoardInfoArea = obj
@property
def chassisInfoArea(self):
return self._ChassisInfoArea
@chassisInfoArea.setter
def chassisInfoArea(self, obj):
self._ChassisInfoArea = obj
@property
def multiRecordArea(self):
return self._multiRecordArea
@multiRecordArea.setter
def multiRecordArea(self, obj):
self._multiRecordArea = obj
@property
def bindata(self):
return self._bindata
@bindata.setter
def bindata(self, obj):
self._bindata = obj
@property
def bodybin(self):
return self._bodybin
@bodybin.setter
def bodybin(self, obj):
self._bodybin = obj
def recalcuteCommonHead(self):
self.bindata = ""
self.offset = self.SUGGESTED_SIZE_COMMON_HEADER
d_print("common Header %d" % self.offset)
d_print("fru eeprom size %d" % self._frusize)
if self.internalUseArea is not None and self.internalUseArea.isPresent:
self.internalUserAreaOffset = self.offset // 8
self.offset += self.internalUseArea.size
d_print("internalUseArea is present offset:%d" % self.offset)
if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent:
self.chassicInfoAreaOffset = self.offset // 8
self.offset += self.chassisInfoArea.size
d_print("chassisInfoArea is present offset:%d" % self.offset)
if self.boardInfoArea is not None and self.boardInfoArea.isPresent:
self.boardInfoAreaOffset = self.offset // 8
self.offset += self.boardInfoArea.size
d_print("boardInfoArea is present offset:%d" % self.offset)
d_print("boardInfoArea is present size:%d" %
self.boardInfoArea.size)
if self.productInfoArea is not None and self.productInfoArea.isPresent:
self.productinfoAreaOffset = self.offset // 8
self.offset += self.productInfoArea.size
d_print("productInfoArea is present offset:%d" % self.offset)
if self.multiRecordArea is not None and self.multiRecordArea.isPresent:
self.multiRecordAreaOffset = self.offset // 8
d_print("multiRecordArea is present offset:%d" % self.offset)
if self.internalUserAreaOffset == self.INITVALUE:
self.internalUserAreaOffset = 0
if self.productinfoAreaOffset == self.INITVALUE:
self.productinfoAreaOffset = 0
if self.chassicInfoAreaOffset == self.INITVALUE:
self.chassicInfoAreaOffset = 0
if self.boardInfoAreaOffset == self.INITVALUE:
self.boardInfoAreaOffset = 0
if self.multiRecordAreaOffset == self.INITVALUE:
self.multiRecordAreaOffset = 0
self.zeroCheckSum = (0x100 - ord(self.version) - self.internalUserAreaOffset - self.chassicInfoAreaOffset - self.productinfoAreaOffset
- self.boardInfoAreaOffset - self.multiRecordAreaOffset) & 0xff
d_print("zerochecksum:%x" % self.zeroCheckSum)
self.data = ""
self.data += chr(self.version[0]) + chr(self.internalUserAreaOffset) + chr(self.chassicInfoAreaOffset) + chr(
self.boardInfoAreaOffset) + chr(self.productinfoAreaOffset) + chr(self.multiRecordAreaOffset) + chr(self.INITVALUE[0]) + chr(self.zeroCheckSum)
self.bindata = self.data + self.bodybin
totallen = len(self.bindata)
d_print("totallen %d" % totallen)
if totallen < self._frusize:
self.bindata = self.bindata.ljust(self._frusize, chr(self.INITVALUE[0]))
else:
raise FruException('bin data more than %d' % self._frusize, -2)
def recalcutebin(self):
self.bodybin = ""
if self.internalUseArea is not None and self.internalUseArea.isPresent:
d_print("internalUseArea present")
self.bodybin += self.internalUseArea.data
if self.chassisInfoArea is not None and self.chassisInfoArea.isPresent:
d_print("chassisInfoArea present")
self.bodybin += self.chassisInfoArea.data
if self.boardInfoArea is not None and self.boardInfoArea.isPresent:
d_print("boardInfoArea present")
self.boardInfoArea.recalcute()
self.bodybin += self.boardInfoArea.data
if self.productInfoArea is not None and self.productInfoArea.isPresent:
d_print("productInfoAreapresent")
self.productInfoArea.recalcute()
self.bodybin += self.productInfoArea.data
if self.multiRecordArea is not None and self.multiRecordArea.isPresent:
d_print("multiRecordArea present")
self.bodybin += self.productInfoArea.data
def recalcute(self, fru_eeprom_size=256):
self._frusize = fru_eeprom_size
self.recalcutebin()
self.recalcuteCommonHead()
def setValue(self, area, field, value):
tmp_area = getattr(self, area, None)
if tmp_area is not None:
tmp_area.fruSetValue(field, value)

378
device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py Executable file → Normal file
View File

@ -1,113 +1,235 @@
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
* onboard temperature sensors
* FAN trays
* PSU
"""
# * onboard temperature sensors
# * FAN trays
# * PSU
#
import os
import xml.etree.ElementTree as ET
import glob
from lxml import etree as ET
import json
from decimal import Decimal
from fru import ipmifru
MAILBOX_DIR = "/sys/bus/i2c/devices/"
PORTS_DIR = "/sys/class/net/"
BOARD_ID_PATH = "/sys/module/platform_common/parameters/dfd_my_type"
BOARD_AIRFLOW_PATH = "/etc/sonic/.airflow"
CONFIG_NAME = "dev.xml"
def getPMCreg(location):
def byteTostr(val):
strtmp = ''
for value in val:
strtmp += chr(value)
return strtmp
def typeTostr(val):
if isinstance(val, bytes):
strtmp = byteTostr(val)
return strtmp
return val
def get_board_id():
if not os.path.exists(BOARD_ID_PATH):
return "NA"
with open(BOARD_ID_PATH) as fd:
id_str = fd.read().strip()
return "0x%x" % (int(id_str, 10))
def getboardairflow():
if not os.path.exists(BOARD_AIRFLOW_PATH):
return "NA"
with open(BOARD_AIRFLOW_PATH) as fd:
airflow_str = fd.read().strip()
data = json.loads(airflow_str)
airflow = data.get("board", "NA")
return airflow
boardid = get_board_id()
boardairflow = getboardairflow()
DEV_XML_FILE_LIST = [
"dev_" + boardid + "_" + boardairflow + ".xml",
"dev_" + boardid + ".xml",
"dev_" + boardairflow + ".xml",
]
def dev_file_read(path, offset, read_len):
retval = "ERR"
val_list = []
msg = ""
ret = ""
fd = -1
if not os.path.exists(path):
return False, "%s %s not found" % (retval, path)
try:
fd = os.open(path, os.O_RDONLY)
os.lseek(fd, offset, os.SEEK_SET)
ret = os.read(fd, read_len)
for item in ret:
val_list.append(item)
except Exception as e:
msg = str(e)
return False, "%s %s" % (retval, msg)
finally:
if fd > 0:
os.close(fd)
return True, val_list
def getPMCreg(location):
retval = 'ERR'
if not os.path.isfile(location):
return "%s %s notfound" % (retval, location)
try:
with open(location, "r") as fd:
with open(location, 'r') as fd:
retval = fd.read()
except Exception:
pass
# logging.error("Unable to open ", location, "file !")
except Exception as error:
return "ERR %s" % str(error)
retval = retval.rstrip("\r\n")
retval = retval.rstrip('\r\n')
retval = retval.lstrip(" ")
return retval
# Get a mailbox register
def get_pmc_register(reg_name):
retval = "ERR"
if reg_name[0:4] == "/rif" or reg_name[0:4] == "/ma1" or reg_name[0:4] == "/eth":
mb_reg_file = PORTS_DIR + reg_name
else:
mb_reg_file = MAILBOX_DIR + reg_name
retval = 'ERR'
mb_reg_file = reg_name
filepath = glob.glob(mb_reg_file)
if len(filepath) == 0:
return "%s %s notfound" % (retval, mb_reg_file)
mb_reg_file = filepath[0] # use first found patch
mb_reg_file = filepath[0]
if not os.path.isfile(mb_reg_file):
# print mb_reg_file, 'not found !'
return "%s %s notfound" % (retval, mb_reg_file)
try:
with open(mb_reg_file, "r") as fd:
with open(mb_reg_file, 'rb') as fd:
retval = fd.read()
except Exception:
pass
# logging.error("Unable to open ", mb_reg_file, "file !")
retval = typeTostr(retval)
except Exception as error:
retval = "%s %s read failed, msg: %s" % (retval, mb_reg_file, str(error))
retval = retval.rstrip("\r\n")
retval = retval.rstrip('\r\n')
retval = retval.lstrip(" ")
return retval
class checktype:
class checktype():
def __init__(self, test1):
self.test1 = test1
@staticmethod
def check(name, location, bit, value, tips, err1):
psu_status = int(get_pmc_register(location), 16)
val = (psu_status & (1 << bit)) >> bit
if val != value:
err1["errmsg"] = tips
err1["code"] = -1
return -1
else:
err1["errmsg"] = "none"
err1["code"] = 0
return 0
@staticmethod
def getValue(location, bit, type):
value_t = get_pmc_register(location)
if value_t.startswith("ERR"):
def getValue(location, bit, data_type, coefficient=1, addend=0):
try:
value_t = get_pmc_register(location)
if value_t.startswith("ERR") or value_t.startswith("NA"):
return value_t
if data_type == 1:
return float('%.1f' % ((float(value_t) / 1000) + addend))
if data_type == 2:
return float('%.1f' % (float(value_t) / 100))
if data_type == 3:
psu_status = int(value_t, 16)
return (psu_status & (1 << bit)) >> bit
if data_type == 4:
return int(value_t, 10)
if data_type == 5:
return float('%.1f' % (float(value_t) / 1000 / 1000))
if data_type == 6:
return Decimal(float(value_t) * coefficient / 1000).quantize(Decimal('0.000'))
return value_t
if type == 1:
return float(value_t) / 1000
elif type == 2:
return float(value_t) / 100
elif type == 3:
psu_status = int(value_t, 16)
return (psu_status & (1 << bit)) >> bit
elif type == 4:
return int(value_t, 10)
else:
except Exception as e:
value_t = "ERR %s" % str(e)
return value_t
# temperature
# fanFRU
@staticmethod
def getTemp(self, name, location, ret_t):
ret2 = self.getValue(location + "temp1_input", " ", 1)
ret3 = self.getValue(location + "temp1_max", " ", 1)
ret4 = self.getValue(location + "temp1_max_hyst", " ", 1)
ret_t["temp1_input"] = ret2
ret_t["temp1_max"] = ret3
ret_t["temp1_max_hyst"] = ret4
def decodeBinByValue(retval):
fru = ipmifru()
fru.decodeBin(retval)
return fru
@staticmethod
def getLM75(name, location, result):
c1 = checktype
r1 = {}
c1.getTemp(c1, name, location, r1)
result[name] = r1
def getfruValue(prob_t, root, val):
try:
ret, binval_bytes = dev_file_read(val, 0, 256)
if ret is False:
return binval_bytes
binval = byteTostr(binval_bytes)
fanpro = {}
ret = checktype.decodeBinByValue(binval)
fanpro['fan_type'] = ret.productInfoArea.productName
fanpro['hw_version'] = str(int(ret.productInfoArea.productVersion, 16))
fanpro['sn'] = ret.productInfoArea.productSerialNumber
fan_display_name_dict = status.getDecodValue(root, "fan_display_name")
fan_name = fanpro['fan_type'].strip()
if len(fan_display_name_dict) == 0:
return fanpro
if fan_name not in fan_display_name_dict:
prob_t['errcode'] = -1
prob_t['errmsg'] = '%s' % ("ERR fan name: %s not support" % fan_name)
else:
fanpro['fan_type'] = fan_display_name_dict[fan_name]
return fanpro
except Exception as error:
return "ERR " + str(error)
@staticmethod
def getslotfruValue(val):
try:
binval = checktype.getValue(val, 0, 0)
if binval.startswith("ERR"):
return binval
slotpro = {}
ret = checktype.decodeBinByValue(binval)
slotpro['slot_type'] = ret.boardInfoArea.boardProductName
slotpro['hw_version'] = ret.boardInfoArea.boardextra1
slotpro['sn'] = ret.boardInfoArea.boardSerialNumber
return slotpro
except Exception as error:
return "ERR " + str(error)
@staticmethod
def getpsufruValue(prob_t, root, val):
try:
psu_match = False
binval = checktype.getValue(val, 0, 0)
if binval.startswith("ERR"):
return binval
psupro = {}
ret = checktype.decodeBinByValue(binval)
psupro['type1'] = ret.productInfoArea.productPartModelName
psupro['sn'] = ret.productInfoArea.productSerialNumber
psupro['hw_version'] = ret.productInfoArea.productVersion
psu_dict = status.getDecodValue(root, "psutype")
psupro['type1'] = psupro['type1'].strip()
if len(psu_dict) == 0:
return psupro
for psu_name, display_name in psu_dict.items():
if psu_name in psupro['type1']:
psupro['type1'] = display_name
psu_match = True
break
if psu_match is not True:
prob_t['errcode'] = -1
prob_t['errmsg'] = '%s' % ("ERR psu name: %s not support" % psupro['type1'])
return psupro
except Exception as error:
return "ERR " + str(error)
class status:
class status():
def __init__(self, productname):
self.productname = productname
@ -119,10 +241,12 @@ class status:
@staticmethod
def getDecodValue(collection, decode):
decodes = collection.find("decode")
decodes = collection.find('decode')
testdecode = decodes.find(decode)
test = {}
for neighbor in testdecode.iter("code"):
if testdecode is None:
return test
for neighbor in testdecode.iter('code'):
test[neighbor.attrib["key"]] = neighbor.attrib["value"]
return test
@ -136,37 +260,67 @@ class status:
for neighbor in root.iter(tagname):
prob_t = {}
prob_t = neighbor.attrib
prob_t["errcode"] = 0
prob_t["errmsg"] = ""
prob_t['errcode'] = 0
prob_t['errmsg'] = ''
for pros in neighbor.iter("property"):
ret = dict(neighbor.attrib.items() + pros.attrib.items())
if "type" not in ret.keys():
ret = dict(list(neighbor.attrib.items()) + list(pros.attrib.items()))
if ret.get('e2type') == 'fru' and ret.get("name") == "fru":
fruval = checktype.getfruValue(prob_t, root, ret["location"])
if isinstance(fruval, str) and fruval.startswith("ERR"):
prob_t['errcode'] = -1
prob_t['errmsg'] = fruval
break
prob_t.update(fruval)
continue
if ret.get("name") == "psu" and ret.get('e2type') == 'fru':
psuval = checktype.getpsufruValue(prob_t, root, ret["location"])
if isinstance(psuval, str) and psuval.startswith("ERR"):
prob_t['errcode'] = -1
prob_t['errmsg'] = psuval
break
prob_t.update(psuval)
continue
if ret.get("gettype") == "config":
prob_t[ret["name"]] = ret["value"]
continue
if 'type' not in ret.keys():
val = "0"
else:
val = ret["type"]
if "bit" not in ret.keys():
if 'bit' not in ret.keys():
bit = "0"
else:
bit = ret["bit"]
s = checktype.getValue(ret["location"], int(bit), int(val))
if 'coefficient' not in ret.keys():
coefficient = 1
else:
coefficient = float(ret["coefficient"])
if 'addend' not in ret.keys():
addend = 0
else:
addend = float(ret["addend"])
s = checktype.getValue(ret["location"], int(bit), int(val), coefficient, addend)
if isinstance(s, str) and s.startswith("ERR"):
prob_t["errcode"] = -1
prob_t["errmsg"] = s
if "default" in ret.keys():
rt = status.getDecodValue(root, ret["decode"])
prob_t["errmsg"] = rt[str(s)]
prob_t['errcode'] = -1
prob_t['errmsg'] = s
break
if 'default' in ret.keys():
rt = status.getDecodValue(root, ret['decode'])
prob_t['errmsg'] = rt[str(s)]
if str(s) != ret["default"]:
prob_t["errcode"] = -1
prob_t['errcode'] = -1
break
else:
if "decode" in ret.keys():
rt = status.getDecodValue(root, ret["decode"])
if (
ret["decode"] == "psutype"
and s.replace("\x00", "").rstrip() not in rt.keys()
): # PSU type detect
prob_t["errcode"] = -1
prob_t["errmsg"] = "%s" % ("The power type does not match, please check whether the power is correct!")
if 'decode' in ret.keys():
rt = status.getDecodValue(root, ret['decode'])
if (ret['decode'] == "psutype" and s.replace("\x00", "").rstrip() not in rt):
prob_t['errcode'] = -1
prob_t['errmsg'] = '%s' % ("ERR psu name: %s not support" %
(s.replace("\x00", "").rstrip()))
else:
s = rt[str(s).replace("\x00", "").rstrip()]
name = ret["name"]
@ -187,46 +341,39 @@ class status:
for i in range(len(L)):
prob_t = {}
prob_t["name"] = getPMCreg("%s/temp%d_label" % (location, i + 1))
prob_t["temp"] = (
float(getPMCreg("%s/temp%d_input" % (location, i + 1))) / 1000
)
prob_t["alarm"] = (
float(getPMCreg("%s/temp%d_crit_alarm" % (location, i + 1))) / 1000
)
prob_t["crit"] = (
float(getPMCreg("%s/temp%d_crit" % (location, i + 1))) / 1000
)
prob_t["temp"] = float(getPMCreg("%s/temp%d_input" % (location, i + 1))) / 1000
prob_t["alarm"] = float(getPMCreg("%s/temp%d_crit_alarm" % (location, i + 1))) / 1000
prob_t["crit"] = float(getPMCreg("%s/temp%d_crit" % (location, i + 1))) / 1000
prob_t["max"] = float(getPMCreg("%s/temp%d_max" % (location, i + 1))) / 1000
a.append(prob_t)
@staticmethod
def getFileName():
return os.path.dirname(os.path.realpath(__file__)) + "/" + CONFIG_NAME
@staticmethod
def getFan(ret):
_filename = status.getFileName()
_tagname = "fan"
status.getvalue(ret, _filename, _tagname)
fpath = os.path.dirname(os.path.realpath(__file__))
for file in DEV_XML_FILE_LIST:
xml = fpath + "/" + file
if os.path.exists(xml):
return xml
return fpath + "/" + CONFIG_NAME
@staticmethod
def checkFan(ret):
_filename = status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
_tagname = "fan"
status.getETValue(ret, _filename, _tagname)
@staticmethod
def getTemp(ret):
_filename = status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
_tagname = "temp"
status.getETValue(ret, _filename, _tagname)
@staticmethod
def getPsu(ret):
_filename = status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
_tagname = "psu"
status.getETValue(ret, _filename, _tagname)
@ -237,8 +384,19 @@ class status:
status.getCPUValue(ret, _filename, _tagname)
@staticmethod
def getMgmtRx(ret):
def getDcdc(ret):
_filename = status.getFileName()
# _filename = "/usr/local/bin/" + status.getFileName()
_tagname = "mgmt_rx"
_tagname = "dcdc"
status.getETValue(ret, _filename, _tagname)
@staticmethod
def getmactemp(ret):
_filename = status.getFileName()
_tagname = "mactemp"
status.getETValue(ret, _filename, _tagname)
@staticmethod
def getmacpower(ret):
_filename = status.getFileName()
_tagname = "macpower"
status.getETValue(ret, _filename, _tagname)

View File

@ -82,6 +82,12 @@
id: 8c10
name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express
Root Port #1 (rev d5)'
- bus: '00'
dev: 1c
fn: '1'
id: 8c12
name: 'PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express
Root Port #2 (rev d5)'
- bus: '00'
dev: 1d
fn: '0'
@ -109,9 +115,8 @@
- bus: '01'
dev: '00'
fn: '0'
id: '1533'
name: 'Ethernet controller: Intel Corporation I210 Gigabit Network Connection (rev
03)'
id: b873
name: 'Ethernet controller: Broadcom Inc. and subsidiaries Device b873 (rev 01)'
- bus: '03'
dev: '00'
fn: '0'
@ -149,8 +154,14 @@
- bus: '07'
dev: '00'
fn: '0'
id: b873
name: 'Ethernet controller: Broadcom Limited Device b873 (rev 01)'
id: '1537'
name: 'Ethernet controller: Intel Corporation I210 Gigabit Backplane Connection
(rev 03)'
- bus: 08
dev: '00'
fn: '0'
id: '7022'
name: 'Memory controller: Xilinx Corporation Device 7022'
- bus: ff
dev: 0b
fn: '0'

View File

@ -1,67 +0,0 @@
{
"XCVR": {
"xcvr_present": {
"i2c": {
"valmap-SFP28": {
"1": true,
"0": false
},
"valmap-QSFP28": {
"1": true,
"0": false
}
}
}
},
"PSU": {
"psu_present": {
"i2c": {
"valmap": {
"1": true,
"0": false
}
}
},
"psu_power_good": {
"i2c": {
"valmap": {
"1": true,
"0": false
}
}
},
"psu_fan_dir": {
"i2c": {
"valmap": {
"F2B": "EXHAUST",
"B2F": "INTAKE"
}
}
},
"PSU_FAN_MAX_SPEED": "18000"
},
"FAN": {
"direction": {
"i2c": {
"valmap": {
"1": "INTAKE",
"0": "EXHAUST"
}
}
},
"present": {
"i2c": {
"valmap": {
"1": true,
"0": false
}
}
},
"duty_cycle_to_pwm": "lambda dc: dc*255/100",
"pwm_to_duty_cycle": "lambda pwm: pwm*100/255"
}
}

View File

@ -0,0 +1,402 @@
{
"chassis": {
"name": "RA-B6510-48V8C",
"thermal_manager": false,
"status_led": {
"controllable": false,
"colors": ["green", "blinking_green", "amber", "blinking_amber"]
},
"components": [
{
"name": "CPU_CPLD"
},
{
"name": "CONNECT_CPLD"
},
{
"name": "CONNECT_CPLD-FAN"
},
{
"name": "MAC_CPLD1"
},
{
"name": "MAC_CPLD2"
},
{
"name": "FPGA"
},
{
"name": "BIOS"
}
],
"fans": [
{
"name": "Fantray1_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray1_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray2_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray2_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray3_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray3_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray4_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
},
{
"name": "Fantray4_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false,
"colors": ["off", "red", "amber", "green"]
}
}
],
"fan_drawers":[
{
"name": "Fantray1",
"num_fans" : 2,
"status_led": {
"controllable": false,
"colors": ["amber", "green", "off"]
},
"fans": [
{
"name": "FanTray1_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
},
{
"name": "FanTray1_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
},
{
"name": "Fantray2",
"num_fans" : 2,
"status_led": {
"controllable": false,
"colors": ["amber", "green", "off"]
},
"fans": [
{
"name": "FanTray2_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
},
{
"name": "FanTray2_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
},
{
"name": "Fantray3",
"num_fans" : 2,
"status_led": {
"controllable": false,
"colors": ["amber", "green", "off"]
},
"fans": [
{
"name": "FanTray3_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
},
{
"name": "FanTray3_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
},
{
"name": "Fantray4",
"num_fans" : 2,
"status_led": {
"controllable": false,
"colors": ["amber", "green", "off"]
},
"fans": [
{
"name": "FanTray4_1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
},
{
"name": "FanTray4_2",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
}
],
"psus": [
{
"name": "Psu1",
"voltage": true,
"current": true,
"power": true,
"max_power": false,
"voltage_high_threshold": true,
"voltage_low_threshold": true,
"temperature": true,
"fans_target_speed": true,
"status_led": {
"controllable": false
},
"fans": [
{
"name": "PSU1_FAN1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
},
{
"name": "Psu2",
"voltage": true,
"current": true,
"power": true,
"max_power": false,
"voltage_high_threshold": true,
"voltage_low_threshold": true,
"temperature": true,
"fans_target_speed": true,
"status_led": {
"controllable": false
},
"fans": [
{
"name": "PSU2_FAN1",
"speed": {
"controllable": true,
"minimum": 50,
"maximum": 100
},
"status_led": {
"available": false
}
}
]
}
],
"thermals": [
{
"name": "ASIC_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "CPU_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "INLET_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "OUTLET_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "MAC_OUT_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "MAC_IN_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "PSU1_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
},
{
"name": "PSU2_TEMP",
"controllable": false,
"low-crit-threshold": true,
"high-crit-threshold": true,
"low-threshold": true,
"high-threshold": true,
"minimum-recorded": true,
"maximum-recorded": true
}
],
"modules": [],
"sfps": []
},
"interfaces": {}
}

View File

@ -0,0 +1,37 @@
{
"chassis": {
"RA-B6510-48V8C": {
"component": {
"CPU_CPLD": {
"firmware": "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/cpu_cpld_upgrade_header.vme",
"version": "27190516"
},
"CONNECT_CPLD": {
"firmware": "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme",
"version": "49191230"
},
"CONNECT_CPLD-FAN": {
"firmware": "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme",
"version": "49191230"
},
"MAC_CPLD1": {
"firmware" : "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme",
"version" : "16190108"
},
"MAC_CPLD2": {
"firmware" : "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme",
"version" : "17200110"
},
"FPGA": {
"firmware": "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/fpga_upgrade_header.bin",
"version": "7a150016"
},
"BIOS": {
"firmware" : "/usr/share/sonic/device/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/bios_upgrade_header.bin",
"version" : "5.11(3BARB029)"
}
}
}
}
}

View File

@ -1,25 +0,0 @@
try:
import os
import sys
import json
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
#from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
# system EEPROM always has device name EEPROM1
self.eeprom_path = pddf_obj.get_path("EEPROM1", "eeprom")
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -1,187 +0,0 @@
# Sample pddf_fanutil file
# All the supported FAN SysFS aattributes are
#- fan<idx>_present
#- fan<idx>_direction
#- fan<idx>_input
#- fan<idx>_pwm
#- fan<idx>_fault
# where idx is in the range [1-12]
#
import os.path
import sys
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
import json
try:
from sonic_fan.fan_base import FanBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class FanUtil(FanBase):
"""PDDF generic FAN util class"""
def __init__(self):
FanBase.__init__(self)
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
self.platform = pddf_obj.get_platform()
self.num_fans = (self.platform['num_fantrays'] * self.platform['num_fans_pertray'])
def get_num_fans(self):
return self.num_fans
def get_presence(self, idx):
# 1 based fan index
if idx < 1 or idx > self.num_fans:
print("Invalid fan index %d\n" % idx)
return False
attr_name = "fan" + str(idx) + "_present"
output = pddf_obj.get_attr_name_output("FAN-CTRL", attr_name)
if not output:
return False
mode = output['mode']
presence = output['status'].rstrip()
vmap = plugin_data['FAN']['present'][mode]['valmap']
if presence in vmap:
status = vmap[presence]
else:
status = False
return status
def get_status(self, idx):
# 1 based fan index
if idx < 1 or idx > self.num_fans:
print("Invalid fan index %d\n" % idx)
return False
speed = self.get_speed(idx)
status = True if (speed != 0) else False
return status
def get_direction(self, idx):
# 1 based fan index
if idx < 1 or idx > self.num_fans:
print("Invalid fan index %d\n" % idx)
return None
attr = "fan" + str(idx) + "_direction"
output = pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return None
mode = output['mode']
val = output['status']
val = val.rstrip()
vmap = plugin_data['FAN']['direction'][mode]['valmap']
if val in vmap:
direction = vmap[val]
else:
direction = val
return direction
def get_directions(self):
num_fan = self.get_num_fan()
for i in range(1, num_fan+1):
attr = "fan" + str(i) + "_direction"
output = pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return None
mode = output['mode']
val = output['status']
val = val.rstrip()
vmap = plugin_data['FAN']['direction'][mode]['valmap']
direction = vmap[str(val)]
print("FAN-%d direction is %s" % (i, direction))
return 0
def get_speed(self, idx):
# 1 based fan index
if idx < 1 or idx > self.num_fans:
print("Invalid fan index %d\n" % idx)
return 0
attr = "fan" + str(idx) + "_input"
output = pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return 0
#mode = output['mode']
val = output['status'].rstrip()
if val.isalpha():
return 0
else:
rpm_speed = int(float(val))
return rpm_speed
def get_speeds(self):
num_fan = self.get_num_fan()
ret = "FAN_INDEX\t\tRPM\n"
for i in range(1, num_fan+1):
attr1 = "fan" + str(i) + "_input"
output = pddf_obj.get_attr_name_output("FAN-CTRL", attr1)
if not output:
return ""
#mode = output['mode']
val = output['status'].rstrip()
if val.isalpha():
frpm = 0
else:
frpm = int(val)
ret += "FAN-%d\t\t\t%d\n" % (i, frpm)
return ret
def set_speed(self, val):
if val < 0 or val > 100:
print("Error: Invalid speed %d. Please provide a valid speed percentage" % val)
return False
#num_fan = self.num_fans
if 'duty_cycle_to_pwm' not in plugin_data['FAN']:
print("Setting fan speed is not allowed !")
return False
else:
print("setspeed nothing to do")
return False
#return True
def dump_sysfs(self):
return pddf_obj.cli_dump_dsysfs('fan')
def get_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring FAN(fand)
on this platform.
"""
raise NotImplementedError

View File

@ -1,59 +0,0 @@
import sys
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
class LedUtil:
color_map = {
"STATUS_LED_COLOR_GREEN": "on",
"STATUS_LED_COLOR_RED": "faulty",
"STATUS_LED_COLOR_OFF": "off"
}
def __init__(self):
global pddf_obj
pddf_obj = pddfparse.PddfParse()
self.path = "pddf/devices/led"
self.cur_state_path = "pddf/devices/led/cur_state"
def set_status_led(self, led_device_name, color, color_state="SOLID"):
if (not led_device_name in list(pddf_obj.data.keys())):
status = "ERROR: " + led_device_name + " is not configured"
return (status)
if (not color in list(self.color_map.keys())):
status = "ERROR: Invalid color"
return (status)
index = pddf_obj.data[led_device_name]['dev_attr']['index']
pddf_obj.create_attr('device_name', led_device_name, self.path)
pddf_obj.create_attr('index', index, self.path)
pddf_obj.create_attr(
'color', self.color_map[color], self.cur_state_path)
pddf_obj.create_attr('color_state', color_state, self.cur_state_path)
pddf_obj.create_attr('dev_ops', 'set_status', self.path)
return ("Executed")
def get_status_led(self, led_device_name):
if (not led_device_name in list(pddf_obj.data.keys())):
status = "ERROR: " + led_device_name + " is not configured"
return (status)
index = pddf_obj.data[led_device_name]['dev_attr']['index']
pddf_obj.create_attr('device_name', led_device_name, self.path)
pddf_obj.create_attr('index', index, self.path)
pddf_obj.create_attr('dev_ops', 'get_status', self.path)
color_f = "/sys/kernel/" + self.cur_state_path + "/color"
color_state_f = "/sys/kernel/" + self.cur_state_path + "/color_state"
try:
with open(color_f, 'r') as f:
color = f.read().strip("\r\n")
with open(color_state_f, 'r') as f:
color_state = f.read().strip("\r\n")
except IOError:
status = "ERROR :" + color_f + " open failed"
return (status)
status = "%s-%s:\t%s %s\n" % (led_device_name,
index, color, color_state)
return (status)

View File

@ -1,270 +0,0 @@
#
# Sample pddf_psuutil file
#
# All the supported PSU SysFS aattributes are
#- psu_present
#- psu_model_name
#- psu_power_good
#- psu_mfr_id
#- psu_serial_num
#- psu_fan_dir
#- psu_v_out
#- psu_i_out
#- psu_p_out
#- psu_fan1_speed_rpm
#
import os.path
import sys
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
import json
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""PDDF generic PSU util class"""
def __init__(self):
PsuBase.__init__(self)
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
self.platform = pddf_obj.get_platform()
def get_num_psus(self):
return int(self.platform['num_psus'])
def get_psu_status(self, index):
if index is None:
return False
device = "PSU" + "%d" % index
output = pddf_obj.get_attr_name_output(device, "psu_power_good")
if not output:
return False
mode = output['mode']
val = output['status']
val = val.rstrip()
vmap = plugin_data['PSU']['psu_power_good'][mode]['valmap']
if val in vmap:
return vmap[val]
else:
return False
def get_psu_presence(self, index):
if index is None:
return False
status = 0
device = "PSU" + "%d" % index
output = pddf_obj.get_attr_name_output(device, "psu_present")
if not output:
return False
mode = output['mode']
status = output['status']
vmap = plugin_data['PSU']['psu_present'][mode]['valmap']
if status.rstrip('\n') in vmap:
return vmap[status.rstrip('\n')]
else:
return False
def get_powergood_status(self, idx):
if idx is None:
return False
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return False
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_power_good")
if not output:
return False
mode = output['mode']
status = output['status']
vmap = plugin_data['PSU']['psu_power_good'][mode]['valmap']
if status.rstrip('\n') in vmap:
return vmap[status.rstrip('\n')]
else:
return False
def get_model(self, idx):
if idx is None:
return None
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return None
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_model_name")
if not output:
return None
model = output['status']
# strip_non_ascii
stripped = (c for c in model if 0 < ord(c) < 127)
model = ''.join(stripped)
return model.rstrip('\n')
def get_mfr_id(self, idx):
if idx is None:
return None
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return None
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_mfr_id")
if not output:
return None
mfr = output['status']
return mfr.rstrip('\n')
def get_serial(self, idx):
if idx is None:
return None
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return None
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_serial_num")
if not output:
return None
serial = output['status']
return serial.rstrip('\n')
def get_direction(self, idx):
if idx is None:
return None
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return None
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_fan_dir")
if not output:
return None
mode = output['mode']
direction = output['status'].rstrip('\n')
vmap = plugin_data['PSU']['psu_fan_dir'][mode]['valmap']
if direction in vmap:
airflow_dir_real = vmap[direction]
else:
airflow_dir_real = direction
return airflow_dir_real
def get_output_voltage(self, idx):
if idx is None:
return 0.0
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return 0.0
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_v_out")
if not output:
return 0.0
v_out = output['status']
# value returned by the psu driver is in mV
return float(v_out)/1000
def get_output_current(self, idx):
if idx is None:
return 0.0
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return 0.0
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_i_out")
if not output:
return 0.0
i_out = output['status']
# current in mA
return float(i_out)/1000
def get_output_power(self, idx):
if idx is None:
return 0.0
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return 0.0
device = "PSU"+"%d" % (idx)
output = pddf_obj.get_attr_name_output(device, "psu_p_out")
if not output:
return 0.0
p_out = output['status']
# power is returned in micro watts
return float(p_out)/1000000
def get_fan_rpm(self, idx, fan_idx):
if idx is None or fan_idx is None:
return 0
if idx < 1 or idx > self.platform['num_psus']:
print("Invalid index %d\n" % idx)
return 0
device = "PSU"+"%d" % (idx)
num_fans = pddf_obj.get_num_psu_fans(device)
if fan_idx < 1 or fan_idx > num_fans:
print("Invalid PSU-fan index %d\n" % fan_idx)
return 0
output = pddf_obj.get_attr_name_output(device, "psu_fan"+str(fan_idx)+"_speed_rpm")
if not output:
return 0
#mode = output['mode']
output['status'] = output['status'].rstrip()
if output['status'].isalpha():
return 0
else:
speed = int(output['status'])
return speed
def dump_sysfs(self):
return pddf_obj.cli_dump_dsysfs('psu')

View File

@ -1,236 +1,243 @@
import os.path
import sys
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
import json
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#
try:
import time
from ctypes import create_string_buffer
import os
import traceback
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
raise ImportError("%s - required module not found" % str(e))
class SfpUtil(SfpUtilBase):
"""Platform generic PDDF SfpUtil class"""
"""Platform-specific SfpUtil class"""
PORT_START = 1
PORT_END = 56
PORTS_IN_BLOCK = 57
EEPROM_OFFSET = 32
SFP_DEVICE_TYPE = "optoe2"
QSFP_DEVICE_TYPE = "optoe1"
I2C_MAX_ATTEMPT = 3
_port_to_eeprom_mapping = {}
_port_start = 0
_port_end = 0
_port_to_type_mapping = {}
_qsfp_ports = []
_sfp_ports = []
def __init__(self):
SfpUtilBase.__init__(self)
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
self.platform = pddf_obj.get_platform()
self._port_start = 0
self._port_end = self.get_num_ports()
for port_num in range(self._port_start, self._port_end):
device = "PORT" + "%d" % (port_num+1)
port_eeprom_path = pddf_obj.get_path(device, "eeprom")
self._port_to_eeprom_mapping[port_num] = port_eeprom_path
port_type = pddf_obj.get_device_type(device)
self._port_to_type_mapping[port_num] = port_type
self.populate_port_type(port_num)
def get_num_ports(self):
return int(self.platform['num_ports'])
def is_valid_port(self, port_num):
if port_num < self._port_start or port_num > self._port_end:
return False
else:
return True
def get_presence(self, port_num):
if port_num < self._port_start or port_num > self._port_end:
return False
device = "PORT" + "%d" % (port_num+1)
output = pddf_obj.get_attr_name_output(device, 'xcvr_present')
if not output:
return False
#mode = output['mode']
modpres = output['status'].rstrip()
if 'XCVR' in plugin_data:
if 'xcvr_present' in plugin_data['XCVR']:
ptype = self._port_to_type_mapping[port_num]
vtype = 'valmap-'+ptype
if vtype in plugin_data['XCVR']['xcvr_present']:
vmap = plugin_data['XCVR']['xcvr_present'][vtype]
if modpres in vmap:
return vmap[modpres]
else:
return False
# if plugin_data doesn't specify anything regarding Transceivers
if modpres == '1':
return True
return False
def populate_port_type(self, port):
if self._port_to_type_mapping[port] == 'QSFP' or self._port_to_type_mapping[port] == 'QSFP28':
self._qsfp_ports.append(port)
elif self._port_to_type_mapping[port] == 'SFP' or self._port_to_type_mapping[port] == 'SFP28':
self._sfp_ports.append(port)
port_to_i2cbus_mapping ={}
@property
def port_start(self):
return self._port_start
return self.PORT_START
@property
def port_end(self):
return (self._port_end - 1)
return self.PORT_END
@property
def qsfp_ports(self):
return range(49, self.PORTS_IN_BLOCK)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
@property
def qsfp_ports(self):
return self._qsfp_ports
def __init__(self):
for x in range(self.PORT_START, self.PORTS_IN_BLOCK):
self.port_to_i2cbus_mapping[x] = x + self.EEPROM_OFFSET - 1
SfpUtilBase.__init__(self)
def reset(self, port_num):
if port_num < self._port_start or port_num > self._port_end:
return False
def _sfp_read_file_path(self, file_path, offset, num_bytes):
attempts = 0
while attempts < self.I2C_MAX_ATTEMPT:
try:
file_path.seek(offset)
read_buf = file_path.read(num_bytes)
except Exception:
attempts += 1
time.sleep(0.05)
return True, read_buf
return False, None
device = "PORT" + "%d" % (port_num+1)
port_ps = pddf_obj.get_path(device, "xcvr_reset")
if port_ps is None:
def _sfp_eeprom_present(self, sysfs_sfp_i2c_client_eeprompath, offset):
"""Tries to read the eeprom file to determine if the
device/sfp is present or not. If sfp present, the read returns
valid bytes. If not, read returns error 'Connection timed out"""
if not os.path.exists(sysfs_sfp_i2c_client_eeprompath):
return False
with open(sysfs_sfp_i2c_client_eeprompath, "rb", buffering=0) as sysfsfile:
rv, buf = self._sfp_read_file_path(sysfsfile, offset, 1)
return rv
def _add_new_sfp_device(self, sysfs_sfp_i2c_adapter_path, devaddr, devtype):
try:
sysfs_nd_path = "%s/new_device" % sysfs_sfp_i2c_adapter_path
# Write device address to new_device file
nd_str = "%s %s" % (devtype, hex(devaddr))
with open(sysfs_nd_path, "w") as nd_file:
nd_file.write(nd_str)
except Exception as err:
print("Error writing to new device file: %s" % str(err))
return 1
else:
return 0
def _get_port_eeprom_path(self, port_num, devid):
sysfs_i2c_adapter_base_path = ""
if port_num in self.port_to_eeprom_mapping:
sysfs_sfp_i2c_client_eeprom_path = self.port_to_eeprom_mapping[port_num]
else:
sysfs_i2c_adapter_base_path = "/sys/class/i2c-adapter"
i2c_adapter_id = self._get_port_i2c_adapter_id(port_num)
if i2c_adapter_id is None:
print("Error getting i2c bus num")
return None
# Get i2c virtual bus path for the sfp
sysfs_sfp_i2c_adapter_path = "%s/i2c-%s" % (sysfs_i2c_adapter_base_path,
str(i2c_adapter_id))
# If i2c bus for port does not exist
if not os.path.exists(sysfs_sfp_i2c_adapter_path):
print("Could not find i2c bus %s. Driver not loaded?" % sysfs_sfp_i2c_adapter_path)
return None
sysfs_sfp_i2c_client_path = "%s/%s-00%s" % (sysfs_sfp_i2c_adapter_path,
str(i2c_adapter_id),
hex(devid)[-2:])
# If sfp device is not present on bus, Add it
if not os.path.exists(sysfs_sfp_i2c_client_path):
if port_num in self.qsfp_ports:
ret = self._add_new_sfp_device(
sysfs_sfp_i2c_adapter_path, devid, self.QSFP_DEVICE_TYPE)
else:
ret = self._add_new_sfp_device(
sysfs_sfp_i2c_adapter_path, devid, self.SFP_DEVICE_TYPE)
if ret != 0:
print("Error adding sfp device")
return None
sysfs_sfp_i2c_client_eeprom_path = "%s/eeprom" % sysfs_sfp_i2c_client_path
return sysfs_sfp_i2c_client_eeprom_path
def _read_eeprom_specific_bytes(self, sysfsfile_eeprom, offset, num_bytes):
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append("0x00")
rv, raw = self._sfp_read_file_path(sysfsfile_eeprom, offset, num_bytes)
if rv is False:
return None
try:
reg_file = open(port_ps, 'w')
except IOError as e:
print("Error: unable to open file: %s" % str(e))
for n in range(0, num_bytes):
eeprom_raw[n] = hex(raw[n])[2:].zfill(2)
except Exception:
return None
return eeprom_raw
def get_eeprom_dom_raw(self, port_num):
if port_num in self.qsfp_ports:
# QSFP DOM EEPROM is also at addr 0x50 and thus also stored in eeprom_ifraw
return None
# Read dom eeprom at addr 0x51
return self._read_eeprom_devid(port_num, self.IDENTITY_EEPROM_ADDR, 256)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
presence_path = "/sys/wb_plat/sff/sff%d/present" % port_num
try:
reg_file.seek(0)
reg_file.write('1')
time.sleep(1)
reg_file.seek(0)
reg_file.write('0')
reg_file.close()
with open(presence_path, "rb") as data:
presence_data = data.read(2)
if presence_data == "":
return False
result = int(presence_data, 16)
except IOError:
return False
if result == 1:
return True
except IOError as e:
return False
return False
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
return False
if not self.get_presence(port_num):
return False
device = "PORT" + "%d" % (port_num+1)
output = pddf_obj.get_attr_name_output(device, 'xcvr_lpmode')
if not output:
if port_num not in self.qsfp_ports:
return False # Read from eeprom only for QSFP ports
try:
eeprom = None
eeprom = open(self.port_to_eeprom_mapping[port_num], "rb")
# check for valid connector type
eeprom.seek(2)
ctype = eeprom.read(1)
if ctype in ['21', '23']:
return False
eeprom.seek(93)
lpmode = ord(eeprom.read(1))
if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
else:
#mode = output['mode']
status = int(output['status'].rstrip())
if status == 1:
return True
else:
return False
return True
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self._port_start or port_num > self._port_end:
return True
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom
return True
device = "PORT" + "%d" % (port_num+1)
port_ps = pddf_obj.get_path(device, "xcvr_lpmode")
if port_ps is None:
if port_num not in self.qsfp_ports:
return False # Write to eeprom only for QSFP ports
def get_transceiver_change_event(self, timeout=0):
return False, {}
def get_highest_temperature(self):
offset = 0
hightest_temperature = -9999
presence_flag = False
read_eeprom_flag = False
temperature_valid_flag = False
for port in range(49, self.PORTS_IN_BLOCK):
if self.get_presence(port) is False:
continue
presence_flag = True
if port in self.qsfp_ports:
offset = 22
else:
offset = 96
eeprom_path = self._get_port_eeprom_path(port, 0x50)
try:
eeprom = None
eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b")
# check for valid connector type
eeprom.seek(2)
ctype = eeprom.read(1)
if ctype in ['21', '23']:
return False
with open(eeprom_path, mode="rb", buffering=0) as eeprom:
read_eeprom_flag = True
eeprom_raw = self._read_eeprom_specific_bytes(eeprom, offset, 2)
msb = int(eeprom_raw[0], 16)
lsb = int(eeprom_raw[1], 16)
# Fill in write buffer
regval = 0x3 if lpmode else 0x1 # 0x3:Low Power Mode, 0x1:High Power Mode
buffer = create_string_buffer(1)
buffer[0] = chr(regval)
result = (msb << 8) | (lsb & 0xff)
result = float(result / 256.0)
if -50 <= result <= 200:
temperature_valid_flag = True
hightest_temperature = max(hightest_temperature, result)
except Exception:
print(traceback.format_exc())
# Write to eeprom
eeprom.seek(93)
eeprom.write(buffer[0])
return True
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
else:
try:
f = open(port_ps, 'w')
if lpmode:
f.write('1')
else:
f.write('0')
f.close()
return True
except IOError as e:
return False
# all port not presence
if presence_flag is False:
hightest_temperature = -10000
def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError
# all port read eeprom fail
elif read_eeprom_flag is False:
hightest_temperature = -9999
def dump_sysfs(self):
return pddf_obj.cli_dump_dsysfs('xcvr')
# all port temperature invalid
elif read_eeprom_flag is True and temperature_valid_flag is False:
hightest_temperature = -10000
hightest_temperature = round(hightest_temperature, 2)
return hightest_temperature

View File

@ -0,0 +1,311 @@
#
# ssd_util.py
#
# Generic implementation of the SSD health API
# SSD models supported:
# - InnoDisk
# - StorFly
# - Virtium
try:
import re
import os
import subprocess
from sonic_platform_base.sonic_ssd.ssd_base import SsdBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
SMARTCTL = "smartctl {} -a"
INNODISK = "iSmart -d {}"
VIRTIUM = "SmartCmd -m {}"
DISK_LIST_CMD = "fdisk -l -o Device"
DISK_FREE_CMD = "df -h"
MOUNT_CMD = "mount"
NOT_AVAILABLE = "N/A"
PE_CYCLE = 3000
FAIL_PERCENT = 95
# Set Vendor Specific IDs
INNODISK_HEALTH_ID = 169
INNODISK_TEMPERATURE_ID = 194
class SsdUtil(SsdBase):
"""
Generic implementation of the SSD health API
"""
model = NOT_AVAILABLE
serial = NOT_AVAILABLE
firmware = NOT_AVAILABLE
temperature = NOT_AVAILABLE
health = NOT_AVAILABLE
remaining_life = NOT_AVAILABLE
sata_rate = NOT_AVAILABLE
ssd_info = NOT_AVAILABLE
vendor_ssd_info = NOT_AVAILABLE
def __init__(self, diskdev):
self.vendor_ssd_utility = {
"Generic" : { "utility" : SMARTCTL, "parser" : self.parse_generic_ssd_info },
"InnoDisk" : { "utility" : INNODISK, "parser" : self.parse_innodisk_info },
"M.2" : { "utility" : INNODISK, "parser" : self.parse_innodisk_info },
"StorFly" : { "utility" : VIRTIUM, "parser" : self.parse_virtium_info },
"Virtium" : { "utility" : VIRTIUM, "parser" : self.parse_virtium_info }
}
"""
The dict model_attr keys relate the vendors
LITEON : "ER2-GD","AF2MA31DTDLT"
Intel : "SSDSCKKB"
SMI : "SM619GXC"
samsung: "MZNLH"
ADATA : "IM2S3134N"
"""
self.model_attr = {
"ER2-GD" : { "temperature" : "\n190\s+(.+?)\n", "remainingLife" : "\n202\s+(.+?)\n" },
"AF2MA31DTDLT" : { "temperature" : "\n194\s+(.+?)\n", "remainingLife" : "\n202\s+(.+?)\n" },
"SSDSCK" : { "temperature" : "\n194\s+(.+?)\n", "remainingLife" : "\n233\s+(.+?)\n" },
"SM619GXC" : { "temperature" : "\n194\s+(.+?)\n", "remainingLife" : "\n169\s+(.+?)\n" },
"MZNLH" : { "temperature" : "\n190\s+(.+?)\n", "remainingLife" : "\n245\s+(.+?)\n" },
"IM2S3134N" : { "temperature" : "\n194\s+(.+?)\n", "remainingLife" : "\n231\s+(.+?)\n" }
}
self.key_list = list(self.model_attr.keys())
self.attr_info_rule = "[\s\S]*SMART Attributes Data Structure revision number: 1|SMART Error Log Version[\s\S]*"
self.dev = diskdev
# Generic part
self.fetch_generic_ssd_info(diskdev)
self.parse_generic_ssd_info()
self.fetch_vendor_ssd_info(diskdev, "Generic")
# Known vendor part
if self.model:
model_short = self.model.split()[0]
if model_short in self.vendor_ssd_utility:
self.fetch_vendor_ssd_info(diskdev, model_short)
self.parse_vendor_ssd_info(model_short)
else:
# No handler registered for this disk model
pass
else:
# Failed to get disk model
self.model = "Unknown"
def _execute_shell(self, cmd):
process = subprocess.Popen(cmd.split(), universal_newlines=True, stdout=subprocess.PIPE)
output, error = process.communicate()
exit_code = process.returncode
if exit_code:
return None
return output
def _parse_re(self, pattern, buffer):
res_list = re.findall(pattern, str(buffer))
return res_list[0] if res_list else NOT_AVAILABLE
def fetch_generic_ssd_info(self, diskdev):
self.ssd_info = self._execute_shell(self.vendor_ssd_utility["Generic"]["utility"].format(diskdev))
# Health and temperature values may be overwritten with vendor specific data
def parse_generic_ssd_info(self):
if "nvme" in self.dev:
self.model = self._parse_re('Model Number:\s*(.+?)\n', self.ssd_info)
health_raw = self._parse_re('Percentage Used\s*(.+?)\n', self.ssd_info)
if health_raw == NOT_AVAILABLE:
self.health = NOT_AVAILABLE
else:
health_raw = health_raw.split()[-1]
self.health = 100 - float(health_raw.strip('%'))
temp_raw = self._parse_re('Temperature\s*(.+?)\n', self.ssd_info)
if temp_raw == NOT_AVAILABLE:
self.temperature = NOT_AVAILABLE
else:
temp_raw = temp_raw.split()[-2]
self.temperature = float(temp_raw)
else:
self.model = self._parse_re('Device Model:\s*(.+?)\n', self.ssd_info)
model_key = ""
for key in self.key_list:
if re.search(key, self.model):
model_key = key
break
if model_key != "":
self.remaining_life = self._parse_re(self.model_attr[model_key]["remainingLife"], re.sub(self.attr_info_rule,"",self.ssd_info)).split()[2]
self.temperature = self._parse_re(self.model_attr[model_key]["temperature"], re.sub(self.attr_info_rule,"",self.ssd_info)).split()[8]
self.health = self.remaining_life
# Get the LITEON ssd health value by (PE CYCLE - AVG ERASE CYCLE )/(PE CYCLE)
if model_key in ["ER2-GD", "AF2MA31DTDLT"]:
avg_erase = int(self._parse_re('\n173\s+(.+?)\n' ,re.sub(self.attr_info_rule,"",self.ssd_info)).split()[-1])
self.health = int(round((PE_CYCLE - avg_erase)/PE_CYCLE*100,0))
if self.remaining_life != NOT_AVAILABLE and int(self.remaining_life) < FAIL_PERCENT:
self.remaining_life = "Fail"
self.sata_rate = self._parse_re('SATA Version is:.*current: (.+?)\)\n', self.ssd_info)
self.serial = self._parse_re('Serial Number:\s*(.+?)\n', self.ssd_info)
self.firmware = self._parse_re('Firmware Version:\s*(.+?)\n', self.ssd_info)
def parse_innodisk_info(self):
if self.vendor_ssd_info:
self.health = self._parse_re('Health:\s*(.+?)%', self.vendor_ssd_info)
self.temperature = self._parse_re('Temperature\s*\[\s*(.+?)\]', self.vendor_ssd_info)
else:
if self.health == NOT_AVAILABLE:
health_raw = self.parse_id_number(INNODISK_HEALTH_ID)
self.health = health_raw.split()[-1]
if self.temperature == NOT_AVAILABLE:
temp_raw = self.parse_id_number(INNODISK_TEMPERATURE_ID)
self.temperature = temp_raw.split()[-6]
def parse_virtium_info(self):
if self.vendor_ssd_info:
self.temperature = self._parse_re('Temperature_Celsius\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
nand_endurance = self._parse_re('NAND_Endurance\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
avg_erase_count = self._parse_re('Average_Erase_Count\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
try:
self.health = 100 - (float(avg_erase_count) * 100 / float(nand_endurance))
except (ValueError, ZeroDivisionError):
# Invalid avg_erase_count or nand_endurance.
pass
def fetch_vendor_ssd_info(self, diskdev, model):
self.vendor_ssd_info = self._execute_shell(self.vendor_ssd_utility[model]["utility"].format(diskdev))
def parse_vendor_ssd_info(self, model):
self.vendor_ssd_utility[model]["parser"]()
def check_readonly2(self, partition, filesystem):
# parse mount cmd output info
mount_info = self._execute_shell(MOUNT_CMD)
for line in mount_info.split('\n'):
column_list = line.split()
if line == '':
continue
if column_list[0] == partition and column_list[2] == filesystem:
if column_list[5].split(',')[0][1:] == "ro":
return partition
else:
return NOT_AVAILABLE
return NOT_AVAILABLE
def check_readonly(self, partition, filesystem):
ret = os.access(filesystem, os.W_OK)
if ret == False:
return partition
else:
return NOT_AVAILABLE
def get_health(self):
"""
Retrieves current disk health in percentages
Returns:
A float number of current ssd health
e.g. 83.5
"""
return float(self.health)
def get_temperature(self):
"""
Retrieves current disk temperature in Celsius
Returns:
A float number of current temperature in Celsius
e.g. 40.1
"""
return float(self.temperature)
def get_model(self):
"""
Retrieves model for the given disk device
Returns:
A string holding disk model as provided by the manufacturer
"""
return self.model
def get_firmware(self):
"""
Retrieves firmware version for the given disk device
Returns:
A string holding disk firmware version as provided by the manufacturer
"""
return self.firmware
def get_serial(self):
"""
Retrieves serial number for the given disk device
Returns:
A string holding disk serial number as provided by the manufacturer
"""
return self.serial
def get_sata_rate(self):
"""
Retrieves SATA rate for the given disk device
Returns:
A string holding current SATA rate as provided by the manufacturer
"""
return self.sata_rate
def get_remaining_life(self):
"""
Retrieves remaining life for the given disk device
Returns:
A string holding disk remaining life as provided by the manufacturer
"""
return self.remaining_life
def get_vendor_output(self):
"""
Retrieves vendor specific data for the given disk device
Returns:
A string holding some vendor specific disk information
"""
return self.vendor_ssd_info
def parse_id_number(self, id):
return self._parse_re('{}\s*(.+?)\n'.format(id), self.ssd_info)
def get_readonly_partition(self):
"""
Check the partition mount filesystem is readonly status,then output the result.
Returns:
The readonly partition list
"""
ro_partition_list = []
partition_list = []
# parse fdisk cmd output info
disk_info = self._execute_shell(DISK_LIST_CMD)
begin_flag = False
for line in disk_info.split('\n'):
if line == "Device":
begin_flag = True
continue
if begin_flag:
if line != "":
partition_list.append(line)
else:
break
# parse df cmd output info
disk_free = self._execute_shell(DISK_FREE_CMD)
disk_dict = {}
line_num = 0
for line in disk_free.split('\n'):
line_num = line_num + 1
if line_num == 1 or line == "":
continue
column_list = line.split()
disk_dict[column_list[0]] = column_list[5]
# get partition which is readonly
for partition in partition_list:
if partition in disk_dict:
ret = self.check_readonly(partition, disk_dict[partition])
if (ret != NOT_AVAILABLE):
ro_partition_list.append(ret)
return ro_partition_list

View File

@ -1,82 +0,0 @@
import os.path
import sys
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
import json
class SYSStatusUtil():
"""Platform-specific SYSStatus class"""
def __init__(self):
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
def get_board_info(self):
device = "SYSSTATUS"
node = pddf_obj.get_path(device, "board_info")
if node is None:
return False
try:
with open(node, 'r') as f:
status = f.read()
print("board_info : %s" % status)
except IOError:
return False
def get_cpld_versio(self):
device = "SYSSTATUS"
node = pddf_obj.get_path(device, "cpld1_version")
if node is None:
return False
try:
with open(node, 'r') as f:
status = f.read()
print("cpld1_version : %s" % status)
except IOError:
return False
def get_power_module_status(self):
device = "SYSSTATUS"
node = pddf_obj.get_path(device, "power_module_status")
if node is None:
return False
try:
with open(node, 'r') as f:
status = f.read()
print("power_module_status : %s" % status)
except IOError:
return False
def get_system_reset_status(self):
device = "SYSSTATUS"
for i in range(1, 8):
node = pddf_obj.get_path(device, "system_reset"+str(i))
if node is None:
return False
try:
with open(node, 'r') as f:
status = f.read()
print("system_reset%s : %s" % (i, status))
except IOError:
print("system_reset%s not supported" % i)
def get_misc_status(self):
device = "SYSSTATUS"
for i in range(1, 3):
node = pddf_obj.get_path(device, "misc"+str(i))
if node is None:
return False
try:
with open(node, 'r') as f:
status = f.read()
print("misc%s : %s" % (i, status))
except IOError:
print("system_reset%s not supported" % i)
def dump_sysfs(self):
return pddf_obj.cli_dump_dsysfs('sys-status')

View File

@ -1,75 +0,0 @@
import os.path
import sys
import json
sys.path.append('/usr/share/sonic/platform/plugins')
import pddfparse
class ThermalUtil:
def __init__(self):
global pddf_obj
global plugin_data
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)) + '/../pddf/pd-plugin.json')) as pd:
plugin_data = json.load(pd)
pddf_obj = pddfparse.PddfParse()
self.platform = pddf_obj.get_platform()
self.num_thermals = self.platform['num_temps']
self.info = []
def get_num_thermals(self):
return (self.num_thermals)
def get_thermal_info(self):
list = []
pddf_obj.get_device_list(list, "TEMP_SENSOR")
list.sort()
for dev in list:
data = {}
device_name = dev['dev_info']['device_name']
topo_info = dev['i2c']['topo_info']
label = "%s-i2c-%d-%x" % (topo_info['dev_type'],
int(topo_info['parent_bus'], 0), int(topo_info['dev_addr'], 0))
attr_list = dev['i2c']['attr_list']
data['device_name'] = device_name
data['label'] = label
for attr in attr_list:
attr_name = attr['attr_name']
node = pddf_obj.get_path(device_name, attr_name)
if node is None:
return False
try:
with open(node, 'r') as f:
attr_value = int(f.read())
except IOError:
return False
data[attr_name] = attr_value/float(1000)
self.info.append(data)
def show_thermal_temp_values(self, idx):
if idx < 1 or idx > self.num_thermals:
print("Invalid temperature sensor idx %d" % idx)
return None
self.get_thermal_info()
thermal_name = "TEMP"+"%d" % idx
label = ""
value = ""
for temp in self.info:
if thermal_name == temp['device_name']:
label = temp['label']
value = "temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" % (
temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst'])
else:
continue
return (label, value)
def show_temp_values(self):
self.get_thermal_info()
for temp in self.info:
print(temp['label'])
print("temp1\t %+.1f C (high = %+.1f C, hyst = %+.1f C)" %
(temp['temp1_input'], temp['temp1_max'], temp['temp1_max_hyst']))
def dump_sysfs(self):
return pddf_obj.cli_dump_dsysfs('temp-sensors')

View File

@ -1,3 +1,3 @@
{
"skip_ledd": true
}
{
"skip_ledd": true
}

View File

@ -1,21 +0,0 @@
# libsensors configuration file
# ----------------------------------------------
#
bus "i2c-2" "i2c-0-mux (chan_id 0)"
chip "lm75-i2c-2-48"
label temp1 "LM75_0 air_inlet"
set temp1_max 80
set temp1_max_hyst 75
chip "lm75-i2c-2-49"
label temp1 "LM75_1 air_outlet"
set temp1_max 80
set temp1_max_hyst 75
chip "lm75-i2c-2-4a"
label temp1 "LM75_2 hottest"
set temp1_max 80
set temp1_max_hyst 75

View File

@ -1,3 +0,0 @@
{
"eeprom": {"bus": 2, "loc": "0057"}
}

View File

@ -1,60 +0,0 @@
{
"components": [
{
"name": "CPLD1 (MAC Board A)",
"firmware_version": {
"bus": 2,
"addr": 51,
"offset": 0,
"size": 4,
"way": 1,
"format": 7,
"sep": "/"
},
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
"slot": 0
},
{
"name": "CPLD2 (MAC Board B)",
"firmware_version": {
"bus": 2,
"addr": 53,
"offset": 0,
"size": 4,
"way": 1,
"format": 7,
"sep": "/"
},
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
"slot": 0
},
{
"name": "CPLD3 (CONNECT Board A)",
"firmware_version": {
"bus": 2,
"addr": 55,
"offset": 0,
"size": 4,
"way": 1,
"format": 7,
"sep": "/"
},
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
"slot": 0
},
{
"name": "CPLD4 (CPU Board)",
"firmware_version": {
"bus": 0,
"addr": 13,
"offset": 0,
"size": 4,
"way": 1,
"format": 7,
"sep": "/"
},
"desc": "Used for managing IO modules, SFP+ modules and system LEDs",
"slot": 1
}
]
}

View File

@ -1,152 +0,0 @@
{
"fans": [
{
"name": "fan1",
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
"format": 2,
"bit": 0
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
"format": 2,
"bit": 0
},
"hw_version": {"loc": "/sys/bus/i2c/devices/3-0053/fan_hw_version"},
"sn": {"loc": "/sys/bus/i2c/devices/3-0053/fan_sn"},
"led": {
"loc": "/sys/bus/i2c/devices/0-0032/fan0_led",
"format": 6,
"mask": 11
},
"led_colors": {
"green": 9,
"red": 10,
"amber": 3
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan1_input"
},
"speed_setter": {
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
},
"speed_max": 23000
}
]
},
{
"name": "fan2",
"e2loc": {"bus": 4, "addr": 83, "way": "i2c", "size": "256"},
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
"format": 2,
"bit": 1
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
"format": 2,
"bit": 1
},
"hw_version": {"loc": "/sys/bus/i2c/devices/4-0053/fan_hw_version"},
"sn": {"loc": "/sys/bus/i2c/devices/4-0053/fan_sn"},
"led": {
"loc": "/sys/bus/i2c/devices/0-0032/fan1_led",
"format": 6,
"mask": 11
},
"led_colors": {
"green": 9,
"red": 10,
"amber": 3
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan2_input"
},
"speed_setter": {
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
},
"speed_max": 23000
}
]
},
{
"name": "fan3",
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
"format": 2,
"bit": 2
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
"format": 2,
"bit": 2
},
"hw_version": {"loc": "/sys/bus/i2c/devices/5-0053/fan_hw_version"},
"sn": {"loc": "/sys/bus/i2c/devices/5-0053/fan_sn"},
"led": {
"loc": "/sys/bus/i2c/devices/0-0032/fan2_led",
"format": 6,
"mask": 11
},
"led_colors": {
"green": 9,
"red": 10,
"amber": 3
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan3_input"
},
"speed_setter": {
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
},
"speed_max": 23000
}
]
},
{
"name": "fan4",
"e2loc": {"bus": 3, "addr": 83, "way": "i2c", "size": "256"},
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_present",
"format": 2,
"bit": 3
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/fan_status",
"format": 2,
"bit": 3
},
"hw_version": {"loc": "/sys/bus/i2c/devices/6-0053/fan_hw_version"},
"sn": {"loc": "/sys/bus/i2c/devices/6-0053/fan_sn"},
"led": {
"loc": "/sys/bus/i2c/devices/0-0032/fan3_led",
"format": 6,
"mask": 11
},
"led_colors":{
"green": 9,
"red": 10,
"amber": 3
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/2-0037/hwmon/*/fan4_input"
},
"speed_setter": {
"loc": "/sys/bus/i2c/devices/0-0032/fan_speed_set"
},
"speed_max": 23000
}
]
}
]
}

View File

@ -1,134 +0,0 @@
{
"psus": [
{
"name": "psu1",
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 0
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 1
},
"sn": {"loc": "/sys/bus/i2c/devices/7-0050/psu_sn"},
"in_current": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr1_input",
"format": 4
},
"in_voltage": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in1_input",
"format": 4
},
"out_voltage": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/in2_input",
"format": 4
},
"out_current": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/curr2_input",
"format": 4
},
"temperature": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/temp1_input",
"format": 4
},
"hw_version": {"loc": "/sys/bus/i2c/devices/7-0050/psu_hw"},
"psu_type": {"loc": "/sys/bus/i2c/devices/7-0050/psu_type"},
"fans": [
{
"name": "psu_fan1",
"present": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_fault"
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 1
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/fan1_input"
},
"speed_max": 28000
}
]
}
],
"in_power": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power1_input",
"format": 5
},
"out_power": {
"loc": "/sys/bus/i2c/devices/7-0058/hwmon/*/power2_input",
"format": 5
}
},
{
"name": "psu2",
"present": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 4
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 5
},
"sn": {"loc": "/sys/bus/i2c/devices/8-0053/psu_sn"},
"in_current": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr1_input",
"format": 4
},
"in_voltage": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in1_input",
"format": 4
},
"out_voltage": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/in2_input",
"format": 4
},
"out_current": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/curr2_input",
"format": 4
},
"temperature": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/temp1_input",
"format": 4
},
"hw_version": {"loc": "/sys/bus/i2c/devices/8-0053/psu_hw"},
"psu_type": {"loc": "/sys/bus/i2c/devices/8-0053/psu_type"},
"fans": [
{
"name": "psu_fan1",
"present": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_fault"
},
"status": {
"loc": "/sys/bus/i2c/devices/2-0037/psu_status",
"format": 2,
"bit": 5
},
"rotors": [
{
"speed_getter": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/fan1_input"
},
"speed_max": 28000
}
]
}
],
"in_power": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power1_input",
"format": 5
},
"out_power": {
"loc": "/sys/bus/i2c/devices/8-005b/hwmon/*/power2_input",
"format": 5
}
}
]
}

View File

@ -1,130 +0,0 @@
{"thermals": [
{
"name": "INLET TEMP",
"high": {
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": null,
"temperature": {
"loc": "/sys/bus/i2c/devices/2-0048/hwmon/*/temp1_input",
"format": 4
}
},
{
"name": "OUTLET TEMP",
"high": {
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": null,
"temperature": {
"loc": "/sys/bus/i2c/devices/2-0049/hwmon/*/temp1_input",
"format": 4
}
},
{
"name": "BOARD TEMP",
"high": {
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": null,
"temperature": {
"loc": "/sys/bus/i2c/devices/2-004a/hwmon/*/temp1_input",
"format": 4
}
},
{
"name": "PHYSICAL ID 0",
"high": {
"loc": "/sys/class/hwmon/hwmon0/temp1_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": {
"loc": "/sys/class/hwmon/hwmon0/temp1_crit",
"format": 4
},
"temperature": {
"loc": "/sys/class/hwmon/hwmon0/temp1_input",
"format": 4
}
},
{
"name": "CPU CORE 0",
"high": {
"loc": "/sys/class/hwmon/hwmon0/temp2_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": {
"loc": "/sys/class/hwmon/hwmon0/temp2_crit",
"format": 4
},
"temperature": {
"loc": "/sys/class/hwmon/hwmon0/temp2_input",
"format": 4
}
},
{
"name": "CPU CORE 1",
"high": {
"loc": "/sys/class/hwmon/hwmon0/temp3_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": {
"loc": "/sys/class/hwmon/hwmon0/temp3_crit",
"format": 4
},
"temperature": {
"loc": "/sys/class/hwmon/hwmon0/temp3_input",
"format": 4
}
},
{
"name": "CPU CORE 2",
"high": {
"loc": "/sys/class/hwmon/hwmon0/temp4_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": {
"loc": "/sys/class/hwmon/hwmon0/temp4_crit",
"format": 4
},
"temperature": {
"loc": "/sys/class/hwmon/hwmon0/temp4_input",
"format": 4
}
},
{
"name": "CPU CORE 3",
"high": {
"loc": "/sys/class/hwmon/hwmon0/temp5_max",
"format": 4
},
"low": null,
"crit_low": null,
"crit_high": {
"loc": "/sys/class/hwmon/hwmon0/temp5_crit",
"format": 4
},
"temperature": {
"loc": "/sys/class/hwmon/hwmon0/temp5_input",
"format": 4
}
}
]
}

View File

@ -1,43 +0,0 @@
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
"""
* onboard temperature sensors
* FAN trays
* PSU
"""
import time
import datetime
from monitor import status
def doWork():
a=[];
'''
return: [{'status': '1', 'hw_version': '1.00', 'errcode': 0, 'fan_type': 'M6510-FAN-F', 'errmsg': 'OK', 'Speed': '9778', 'id': 'fan1', 'present': '0', 'sn': '1000000000014'},
{'id': 'fan2', 'errmsg': 'not present', 'errcode': -1},
{'id': 'fan3', 'errmsg': 'not present', 'errcode': -1},
{'id': 'fan4', 'errmsg': 'not present', 'errcode': -1}
]
description: 1.get id
2.errcode equal 0 : dev normal
not equal 0 : get errmsg
3.other message add when all check success
'''
status.checkFan(a)
#status.getTemp(a)
#status.getPsu(a)
nowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(nowTime)
print(a)
def run(interval):
while True:
try:
time_remaining = interval - time.time()%interval
time.sleep(time_remaining)
doWork()
except Exception as e:
print(e)
if __name__ == '__main__':
interval = 1
run(interval)

View File

@ -78,9 +78,6 @@ $(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(DELL_S6000_PLATFORM_MODULE) \
$(DELTA_AGC032_PLATFORM_MODULE) \
$(RUIJIE_B6510_48VS8CQ_PLATFORM_MODULE) \
$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE) \
$(RAGILE_RA_B6910_64C_PLATFORM_MODULE) \
$(RAGILE_RA_B6510_32C_PLATFORM_MODULE) \
$(RAGILE_RA_B6920_4S_PLATFORM_MODULE) \
$(NOKIA_IXR7250_PLATFORM_MODULE) \
$(TENCENT_TCS8400_PLATFORM_MODULE) \
$(TENCENT_TCS9400_PLATFORM_MODULE) \

View File

@ -10,25 +10,25 @@ SONIC_DPKG_DEBS += $(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)
SONIC_STRETCH_DEBS += $(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE)
## RA-B6910-64C
RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION = 1.0
export RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION
## RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION = 1.0
## export RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION
RAGILE_RA_B6910_64C_PLATFORM_MODULE = platform-modules-ragile-ra-b6910-64c_$(RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION)_amd64.deb
$(RAGILE_RA_B6910_64C_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6910-64c-r0
$(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6910_64C_PLATFORM_MODULE)))
## RAGILE_RA_B6910_64C_PLATFORM_MODULE = platform-modules-ragile-ra-b6910-64c_$(RAGILE_RA_B6910_64C_PLATFORM_MODULE_VERSION)_amd64.deb
## $(RAGILE_RA_B6910_64C_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6910-64c-r0
## $(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6910_64C_PLATFORM_MODULE)))
## RA-B6510-32C
RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION = 1.0
export RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION
## RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION = 1.0
## export RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION
RAGILE_RA_B6510_32C_PLATFORM_MODULE = platform-modules-ragile-ra-b6510-32c_$(RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION)_amd64.deb
$(RAGILE_RA_B6510_32C_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6510-32c-r0
$(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6510_32C_PLATFORM_MODULE)))
## RAGILE_RA_B6510_32C_PLATFORM_MODULE = platform-modules-ragile-ra-b6510-32c_$(RAGILE_RA_B6510_32C_PLATFORM_MODULE_VERSION)_amd64.deb
## $(RAGILE_RA_B6510_32C_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6510-32c-r0
## $(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6510_32C_PLATFORM_MODULE)))
## RA-B6920-4s
RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION = 1.0
export RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION
## RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION = 1.0
## export RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION
RAGILE_RA_B6920_4S_PLATFORM_MODULE = platform-modules-ragile-ra-b6920-4s_$(RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION)_amd64.deb
$(RAGILE_RA_B6920_4S_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6920-4s-r0
$(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6920_4S_PLATFORM_MODULE)))
## RAGILE_RA_B6920_4S_PLATFORM_MODULE = platform-modules-ragile-ra-b6920-4s_$(RAGILE_RA_B6920_4S_PLATFORM_MODULE_VERSION)_amd64.deb
## $(RAGILE_RA_B6920_4S_PLATFORM_MODULE)_PLATFORM = x86_64-ragile_ra-b6920-4s-r0
## $(eval $(call add_extra_package,$(RAGILE_RA_B6510_48V8C_PLATFORM_MODULE),$(RAGILE_RA_B6920_4S_PLATFORM_MODULE)))

View File

@ -1,5 +1,4 @@
Copyright (C) 2016 Microsoft, Inc
Copyright (C) 2018 Ragile Network Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2

View File

@ -9,33 +9,34 @@ SUB_BUILD_DIR = $(PWD)/build
DIR_KERNEL_SRC = $(PWD)/modules
SCRIPT_DIR = $(PWD)/script
SERVICE_DIR = $(PWD)/service
DEPMOD_CONF_DIR = $(PWD)/depmod_conf
BLACK_DRIVER_CONF_DIR = $(PWD)/modprobe_conf
KBUILD_EXTRA_SYMBOLS += $(DIR_KERNEL_SRC)/Module.symvers
export KBUILD_EXTRA_SYMBOLS
app_dir = $(PWD)/app
app_build_dir = $(app_dir)/build
modules_build_dir = $(DIR_KERNEL_SRC)/build
INSTALL_MODULE_DIR = $(SUB_BUILD_DIR)/$(KERNEL_SRC)/$(INSTALL_MOD_DIR)
INSTALL_SCRIPT_DIR = $(SUB_BUILD_DIR)/usr/local/bin
INSTALL_SERVICE_DIR = $(SUB_BUILD_DIR)/lib/systemd/system
INSTALL_LIB_DIR = $(SUB_BUILD_DIR)/usr/lib/python3.7/dist-packages
INSTALL_DEPMOD_CONF = $(SUB_BUILD_DIR)/etc/depmod.d
INSTALL_LIB_DIR = $(SUB_BUILD_DIR)/usr/lib/python3/dist-packages
INSTALL_BLACK_DRIVER = $(SUB_BUILD_DIR)/etc/modprobe.d
all:
$(MAKE) -C $(KERNEL_SRC)/build M=$(DIR_KERNEL_SRC) modules
$(MAKE) -C $(app_dir)
$(MAKE) -C $(DIR_KERNEL_SRC)
@if [ ! -d ${INSTALL_MODULE_DIR} ]; then mkdir -p ${INSTALL_MODULE_DIR} ;fi
@if [ ! -d ${INSTALL_SCRIPT_DIR} ]; then mkdir -p ${INSTALL_SCRIPT_DIR} ;fi
@if [ ! -d ${INSTALL_SERVICE_DIR} ]; then mkdir -p ${INSTALL_SERVICE_DIR} ;fi
@if [ ! -d ${INSTALL_LIB_DIR} ]; then mkdir -p ${INSTALL_LIB_DIR} ;fi
@if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR} ;fi
@if [ -d $(PWD)/lib/ ]; then cp -r $(PWD)/lib/* ${INSTALL_LIB_DIR2} ;fi
@if [ ! -d ${INSTALL_DEPMOD_CONF} ]; then mkdir -p ${INSTALL_DEPMOD_CONF} ;fi
cp -r $(DEPMOD_CONF_DIR)/* $(INSTALL_DEPMOD_CONF)
cp -r $(DIR_KERNEL_SRC)/*.ko $(INSTALL_MODULE_DIR)
@if [ -d $(PWD)/sonic_platform/ ]; then cp -rf $(PWD)/sonic_platform ${INSTALL_LIB_DIR} ;fi
cp -r $(app_build_dir)/module/*.ko $(INSTALL_MODULE_DIR)
cp -r $(modules_build_dir)/*.ko $(INSTALL_MODULE_DIR)
cp -r $(app_dir)/build/app/* $(INSTALL_SCRIPT_DIR)
cp -r $(SCRIPT_DIR)/* $(INSTALL_SCRIPT_DIR)
cp -r $(SERVICE_DIR)/* $(INSTALL_SERVICE_DIR)
@if [ -d $(INSTALL_SCRIPT_DIR) ]; then chmod +x $(INSTALL_SCRIPT_DIR)/* ;fi
@if [ ! -d ${INSTALL_BLACK_DRIVER} ]; then mkdir -p ${INSTALL_BLACK_DRIVER} ;fi
cp -r $(BLACK_DRIVER_CONF_DIR)/* $(INSTALL_BLACK_DRIVER)
clean:
rm -f ${DIR_KERNEL_SRC}/*.o ${DIR_KERNEL_SRC}/*.ko ${DIR_KERNEL_SRC}/*.mod.c ${DIR_KERNEL_SRC}/.*.cmd
rm -f ${DIR_KERNEL_SRC}/Module.markers ${DIR_KERNEL_SRC}/Module.symvers ${DIR_KERNEL_SRC}/modules.order
rm -rf ${DIR_KERNEL_SRC}/.tmp_versions
rm -rf $(SUB_BUILD_DIR)

View File

@ -0,0 +1,25 @@
pes_parent_dir:=$(shell pwd)/$(lastword $(MAKEFILE_LIST))
pes_parent_dir:=$(shell dirname $(pes_parent_dir))
SUBDIRS=$(shell ls -l | grep ^d | awk '{if($$9 != "build") print $$9}')
INC = -I./inc
COMMON_OUT_PUT := $(shell pwd)/build
common_out_put_dir := $(COMMON_OUT_PUT)/app
common_module_dir := $(COMMON_OUT_PUT)/module/
export common_out_put_dir common_module_dir
all : CHECK $(SUBDIRS)
CHECK :
@echo $(pes_parent_dir)
$(SUBDIRS):ECHO
#@echo $@
make -C $@
ECHO:
@echo $(SUBDIRS)
.PHONY : clean
clean :
-rm -rf $(COMMON_OUT_PUT)

View File

@ -0,0 +1,30 @@
top_srcdir:=$(shell pwd)
#include $(top_srcdir)/Rules.mk
DIR=$(shell pwd)
BUILD_OUTPUT=$(DIR)/tmp
SRCS=$(wildcard *.c)
OBJS=$(patsubst %.c, $(BUILD_OUTPUT)/%.o, $(SRCS))
DEPS=$(patsubst %.o, %.d, $(OBJS))
CFLAGS+=-Wall -W -g -I$(DIR)/include
LDFLAGS=
PROGRAM=dfd_debug
.PHONY: all
all:$(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $(BUILD_OUTPUT)/$(PROGRAM)
@if [ ! -d ${common_out_put_dir} ]; then mkdir -p ${common_out_put_dir} ;fi
cp -p $(BUILD_OUTPUT)/$(PROGRAM) $(common_out_put_dir)
$(OBJS):$(SRCS)
@if [ ! -d ${BUILD_OUTPUT} ]; then mkdir -p ${BUILD_OUTPUT} ;fi
$(CC) -c $(CFLAGS) $(INCLUDE) $(*F).c -o $@
.PHONY: install
install:
@mkdir -p $(common_out_put_dir)
cp -p $(BUILD_OUTPUT)/$(PROGRAM) $(common_out_put_dir)
rebuild: clean all
clean:
@rm -rf $(BUILD_OUTPUT)/*

View File

@ -0,0 +1,43 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <fcntl.h>
#include "dfd_utest.h"
int g_dfd_debug_sw = 0;
int g_dfd_debugpp_sw = 0;
void dfd_debug_set_init(void)
{
FILE *fp;
char buf[10];
mem_clear(buf, sizeof(buf));
fp = fopen(DFD_DEBUGP_DEBUG_FILE, "r");
if (fp != NULL) {
g_dfd_debug_sw = 1;
fclose(fp);
}
fp = fopen(DFD_DEBUGPP_DEBUG_FILE, "r");
if (fp != NULL) {
g_dfd_debugpp_sw = 1;
fclose(fp);
}
return;
}
int main(int argc, char* argv[])
{
dfd_debug_set_init();
dfd_utest_cmd_main(argc, argv);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,103 @@
/* monitor_utest.h */
#ifndef __DFD_UTEST_H__
#define __DFD_UTEST_H__
#include <string.h>
extern int g_dfd_debug_sw;
extern int g_dfd_debugpp_sw;
#define DFD_UTEST_TRUE_FALSE_STRING(flag) ((flag == true) ? "true" : "false")
#define DFD_DEBUG_DBG(fmt, args...) do { \
if (g_dfd_debug_sw) { \
printf("" fmt,\
##args); \
} \
} while (0)
#define DFD_DEBUG_ERROR(fmt, args...) do { \
if (g_dfd_debugpp_sw) { \
printf("" fmt,\
##args); \
} \
} while (0)
#define mem_clear(data, size) memset((data), 0, (size))
typedef enum dfd_rv_s {
DFD_RV_OK = 0,
DFD_RV_INIT_ERR = 1,
DFD_RV_SLOT_INVALID = 2,
DFD_RV_MODE_INVALID = 3,
DFD_RV_MODE_NOTSUPPORT = 4,
DFD_RV_TYPE_ERR = 5,
DFD_RV_DEV_NOTSUPPORT = 6,
DFD_RV_DEV_FAIL = 7,
DFD_RV_INDEX_INVALID = 8,
DFD_RV_NO_INTF = 9,
DFD_RV_NO_NODE = 10,
DFD_RV_NODE_FAIL = 11,
} dfd_rv_t;
#define DFD_DEBUG_BUF_LEN (32)
#define DFD_DEBUGP_DEBUG_FILE "/sbin/.dfd_debugp_flag"
#define DFD_DEBUGPP_DEBUG_FILE "/sbin/.dfd_debugpp_flag"
#define DFD_UTEST_MAX_PARA_NUM (4)
#define DFD_UTEST_TYPE_STRING_LEN (64)
#define DFD_UTEST_MATCH_STRING_LEN (64)
#define DFD_UTEST_HELP_STRING_LEN (256)
#define DFD_UTEST_INVALID_PARA (-1)
#define DFD_UTEST_BUFF_LEN (64)
typedef enum dfd_fpga_cpld_flag_e {
DFD_CPLD_RW_FLAG = 0x00,
DFD_FPGA_RW_FLAG = 0x01,
} dfd_fpga_cpld_flag_t;
typedef int (* dfd_utest_proc_fun)(int argc, char* argv[]);
#define DFD_UTEST_ITEM_ALL \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_I2C_RD, i2c_rd, "i2c_rd [i2c_bus] [slave_addr] [offset] [len]", "i2c_rd [i2c_bus] [slave_addr] [offset] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_I2C_WR, i2c_wr, "i2c_wr [i2c_bus] [slave_addr] [offset] [data0] ... [dataN]", "i2c_wr [i2c_bus] [slave_addr] [offset] [data0] ... [dataN]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_IO_RD, io_rd, "io_rd [offset] [len]", "io_rd [offset] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_IO_WR, io_wr, "io_wr [offset] [data0]... [dataN]", "io_wr [offset] [data0]... [dataN]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_PHYMEM_RD, phymem_rd, "phymem_rd [bit_width] [offset] [len]", "phymem_rd [bit_width] [offset] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_PHYMEM_WR, phymem_wr, "phymem_wr [bit_width] [offset] [data0]... [dataN]", "phymem_wr [bit_width] [offset] [data0]... [dataN]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_KMEM_RD, kmem_rd, "kmem_rd [bit_width] [offset] [len]", "kmem_rd [bit_width] [offset] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_KMEM_WR, kmem_wr, "kmem_wr [bit_width][offset] [data0]... [dataN]", "kmem_wr [bit_width] [offset] [data0]... [dataN]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_I2C_FILE_WR, i2c_file_wr, "i2c_file_wr [i2c_bus] [slave_addr] [offset] [bpt] [filename]", "i2c_file_wr [i2c_bus] [slave_addr] [offset] [bpt] [filename]\nbpt:bytes per times") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_SYSFS_FILE_WR, sysfs_file_wr, "sysfs_file_wr [sysfs_loc] [offset] [filename] [per_wr_byte]", "sysfs_file_wr [sysfs_loc] [offset] [filename] [per_wr_byte]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_SYSFS_FILE_RD, sysfs_file_rd, "sysfs_file_rd [sysfs_loc] [offset] [len]", "sysfs_file_rd [sysfs_loc] [offset] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_SYSFS_FILE_UPG, sysfs_file_upg, "sysfs_file_upg [sysfs_loc] [offset] [filename] [per_wr_byte]", "sysfs_file_upg [sysfs_loc] [offset] [filename] [per_wr_byte]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_I2C_GEN_RD, i2c_gen_rd, "i2c_gen_rd [i2c_bus] [slave_addr] [addr_bitwidth] [offset] [data_bitwidth] [len]", "i2c_gen_rd [i2c_bus] [slave_addr] [addr_bitwidth] [offset] [data_bitwidth] [len]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_I2C_GEN_WR, i2c_gen_wr, "i2c_gen_wr [i2c_bus] [slave_addr] [addr_bitwidth] [offset] [data_bitwidth] [data0]... [dataN]", "i2c_gen_wr [i2c_bus] [slave_addr] [addr_bitwidth] [offset] [data_bitwidth] [data0]... [dataN]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_MSR_RD, msr_rd, "msr_rd [cpu_index] [offset] [width]", "msr_rd [cpu_index] [offset] [width]") \
DFD_UTEST_ITEM(DFD_UTEST_ITEM_SYSFS_DATA_WR, sysfs_data_wr, "sysfs_data_wr [sysfs_loc] [offset] [data0] ... [dataN]", "sysfs_data_wr [sysfs_loc] [offset] [data0] ... [dataN]]") \
#ifdef DFD_UTEST_ITEM
#undef DFD_UTEST_ITEM
#endif
#define DFD_UTEST_ITEM(_id, _type_str, _help_info, _help_info_detail) _id,
typedef enum dfd_utest_item_id_s {
DFD_UTEST_ITEM_ALL
} dfd_utest_item_id_t;
typedef struct {
int utest_type;
char type_str[DFD_UTEST_TYPE_STRING_LEN];
dfd_utest_proc_fun utest_func;
char help_info[DFD_UTEST_HELP_STRING_LEN];
char help_info_detail[DFD_UTEST_HELP_STRING_LEN];
} dfd_utest_t;
void dfd_utest_cmd_main(int argc, char* argv[]);
#ifdef DFD_UTEST_ITEM
#undef DFD_UTEST_ITEM
#endif
#define DFD_UTEST_ITEM(_id, _type_str, _help_info, _help_info_detail) int dfd_utest_##_type_str(int argc, char* argv[]);
DFD_UTEST_ITEM_ALL
#endif

View File

@ -0,0 +1,19 @@
top_srcdir:=$(shell pwd)
include $(top_srcdir)/Rules.mk
firmware-y:=
firmware-y += firmware_driver
firmware-y += firmware_upgrade
.PHONY: all
all: build
.PHONY: build
build: $(firmware-y)
$(foreach dir,$(firmware-y),$(eval $(call compile_dirs,$(dir))))
.PHONY: rpmpkg
rpmpkg:
ifeq ("$(CONFIG_CPLD_UPGRADE_ISPVME)", "y")
#$(RPMPKG) $(install_cpld_dir) firmware-cpld-ispvme.spec git
endif

View File

@ -0,0 +1,42 @@
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
AS ?= $(CROSS)as
LD ?= $(CROSS)ld
STRIP ?= $(CROSS)strip
install_root:=${top_srcdir}/images
install_header_dir:=${install_root}/header
install_adir:=$(install_root)/lib
install_symbol_dir:=$(install_root)/symbol
symbol_files:=$(shell find $(EXPORT_SYMBOL) -name 'Module.symvers')
#
# symbol_files += $(shell find $(install_symbol_dir) -name 'Module.symvers')
# KBUILD_EXTRA_SYMBOLS += $(symbol_files)
# export KBUILD_EXTRA_SYMBOLS
# top root: install_rootfs_dir
install_rootfs_dir:=$(install_root)/rootfs
install_sodir:=$(install_rootfs_dir)/$(INSTALL_SODIR)
install_usr_bin_dir:=$(install_rootfs_dir)/usr/bin
install_sbin_dir:=$(install_rootfs_dir)/sbin
install_etc_dir:=$(install_rootfs_dir)/etc
export INSTALL_MOD_PATH:=$(ROOT)
BUILD_CFLAGS:=$(CFLAGS) -I$(install_header_dir)
BUILD_LDFLAGS:=$(LDFLAGS) -L/$(install_sodir) -L/$(install_adir)
define compile_dirs
.PHONY: $(1)
$(1):
@echo;echo "building $(1)..."
@$(MAKE) -C ${1}
endef
compile.c = $(CC) $(BUILD_CFLAGS) -d -c -o $@ $<
%.o: %.c
$(compile.c)

View File

@ -0,0 +1,19 @@
include $(top_srcdir)/Rules.mk
firmware-y:=
firmware-y += firmware_driver_ispvme
firmware-y += firmware_driver_cpld
firmware-y += firmware_driver_sysfs
.PHONY: all
all: build
.PHONY: build
build: $(firmware-y)
$(foreach dir,$(firmware-y),$(eval $(call compile_dirs,$(dir))))
.PHONY: rpmpkg
rpmpkg:
ifeq ("$(CONFIG_CPLD_UPGRADE_ISPVME)", "y")
#$(RPMPKG) $(install_cpld_dir) firmware-cpld-ispvme.spec git
endif

View File

@ -0,0 +1,23 @@
#include $(top_srcdir)/debian/rules
#KERNELDIR := ${KBUILD_OUTPUT}
PWD = $(shell pwd)
EXTRA_CFLAGS:= -I$(M)/include
MAKEFILE_FILE_PATH = $(abspath $(lastword $(MAKEFILE_LIST)))
FIRMWARE_UPGRADE_PATH = $(abspath $(MAKEFILE_FILE_PATH)/../../include)
EXTRA_CFLAGS+= -I$(FIRMWARE_UPGRADE_PATH)
EXTRA_CFLAGS+= -Wall
firmware_driver_cpld-objs := firmware.o
firmware_driver_cpld-objs += firmware_cpld.o firmware_cpld_upgrade.o
firmware_driver_cpld-objs += jbicomp.o jbijtag.o jbimain.o jbistub.o
#ifndef CONFIG_FRM_PRODUCT_FILE
$(warning $(firmware_driver_cpld-objs))
obj-m := firmware_driver_cpld.o
all:
$(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules
@if [ ! -d $(common_module_dir) ]; then mkdir -p $(common_module_dir) ;fi
cp -p $(PWD)/*.ko $(common_module_dir)

View File

@ -0,0 +1,144 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <firmware.h>
int g_firmware_driver_debug = 0;
module_param(g_firmware_driver_debug, int, S_IRUGO | S_IWUSR);
static LIST_HEAD(drv_list);
static LIST_HEAD(dev_list);
/**
* firmware_driver_register
* function:Registered Device Driver
* @fw_drv:param[in] Driver information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_driver_register(firmware_driver_t *fw_drv)
{
int ret;
if (fw_drv == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Parameter error.\n");
return FIRMWARE_FAILED;
}
ret = platform_driver_register(fw_drv->drv);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: failed to register firmware upgrade driver \n");
return FIRMWARE_FAILED;
}
/* Adds driver information to the driver list */
list_add(&fw_drv->list, &drv_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware upgrade driver register sucess \n");
return FIRMWARE_SUCCESS;
}
/**
* firmware_driver_unregister
* function:unregister Device Driver
* @fw_drv:param[in] Driver information
*/
void firmware_driver_unregister(firmware_driver_t *fw_drv)
{
list_del_init(&fw_drv->list);
platform_driver_unregister(fw_drv->drv);
}
/*
* firmware_get_device_by_minor
* function: Get device information based on minor
*/
firmware_device_t *firmware_get_device_by_minor(int minor)
{
firmware_device_t *tmp;
list_for_each_entry(tmp, &dev_list, list) {
if (tmp->dev.minor == minor) {
return tmp;
}
}
return NULL;
}
/**
* firmware_device_register
* function:Registered Driver Device
* @fw_dev: param[in] Driver information
* return value:success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_device_register(firmware_device_t *fw_dev)
{
int ret;
firmware_device_t *tmp;
if (fw_dev == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Parameter error.\n");
return FIRMWARE_FAILED;
}
/* Check whether the device file name already exists in the device linked list */
list_for_each_entry(tmp, &dev_list, list) {
if (strcmp(tmp->name, fw_dev->name) == 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("devie %s already exists.\n", fw_dev->name);
return FIRMWARE_FAILED;
}
}
/* Registere device */
ret = misc_register(&fw_dev->dev);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("register misc error, ret=%d.\n", ret);
return FIRMWARE_FAILED;
}
/* Adds a device to the device list */
list_add(&fw_dev->list, &dev_list);
return FIRMWARE_SUCCESS;
}
/**
* firmware_device_unregister
* function: unregister Driver Device
*/
void firmware_device_unregister(firmware_device_t *fw_dev)
{
list_del(&fw_dev->list);
misc_deregister(&fw_dev->dev);
}
static int __init firmware_driver_init(void)
{
int ret;
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver init.\n");
ret = firmware_cpld_init();
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware driver init failed.\n");
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}
static void __exit firmware_driver_exit(void)
{
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver exit.\n");
firmware_cpld_exit();
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
return;
}
module_init(firmware_driver_init);
module_exit(firmware_driver_exit);
MODULE_AUTHOR("support");
MODULE_DESCRIPTION("Firmware upgrade driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");

View File

@ -0,0 +1,384 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/of.h>
#include <linux/uaccess.h>
#include <firmware.h>
#include <firmware_cpld.h>
#include <firmware_upgrade.h>
static int firmware_cpld_open(struct inode *inode, struct file *file)
{
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Open cpld device.\n");
frm_dev = firmware_get_device_by_minor(MINOR(inode->i_rdev));
if (frm_dev == NULL) {
return -ENXIO;
}
file->private_data = frm_dev;
return FIRMWARE_SUCCESS;
}
static ssize_t firmware_cpld_read (struct file *file, char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static ssize_t firmware_cpld_write (struct file *file, const char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static loff_t firmware_cpld_llseek(struct file *file, loff_t offset, int origin)
{
return 0;
}
/*
* firmware_cpld_ioctl
* function: ioctl command parsing function
* @file: param[in] device file name
* @cmd: param[in] command
* @arg: param[in] the parameters in the command
* return value: success-FIRMWARE_SUCCESS; fail:other value
*/
static long firmware_cpld_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;
char *buf;
void __user *argp;
char version[FIRMWARE_NAME_LEN];
char chip_name[FIRMWARE_NAME_LEN];
cmd_info_t cmd_info;
firmware_device_t *frm_dev;
firmware_cpld_t *cpld_info;
/* Get device private data */
mem_clear(&cmd_info, sizeof(cmd_info_t));
frm_dev = (firmware_device_t *)file->private_data;
cpld_info = NULL;
if (frm_dev != NULL) {
if (frm_dev->priv != NULL) {
cpld_info = (firmware_cpld_t *)frm_dev->priv;
}
}
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to frm_dev->priv sysfs info.\n");
return FIRMWARE_FAILED;
}
argp = (void __user *)arg;
switch (cmd) {
case FIRMWARE_GET_CHIPNAME:
/* get chip name */
if (copy_from_user(&cmd_info, argp, sizeof(cmd_info_t))) {
return -EFAULT;
}
mem_clear(chip_name, FIRMWARE_NAME_LEN);
ret = fmw_cpld_upg_get_chip_name(frm_dev->chain, cpld_info, chip_name, FIRMWARE_NAME_LEN);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get chip name.\n");
return -ENXIO;
}
if (copy_to_user(cmd_info.data, chip_name, cmd_info.size)) {
return -EFAULT;
}
break;
case FIRMWARE_PROGRAM:
case FIRMWARE_PROGRAM_JBI:
/* firmware upgrade */
if (copy_from_user(&cmd_info, argp, sizeof(cmd_info_t))) {
return -EFAULT;
}
buf = (char *) kzalloc(cmd_info.size + 1, GFP_KERNEL);
if (buf == NULL) {
return -ENOMEM;
}
if (copy_from_user(buf, cmd_info.data, cmd_info.size)) {
kfree(buf);
return -EFAULT;
}
buf[cmd_info.size] = 0;
if (cmd == FIRMWARE_PROGRAM_JBI) {
/* JBI firmware upgrade */
ret = fmw_cpld_upg_program_jbi(frm_dev->chain, cpld_info, buf, cmd_info.size);
} else {
/* ISC firmware upgrade */
ret = fmw_cpld_upg_program(frm_dev->chain, cpld_info, buf, cmd_info.size);
}
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to program cpld.\n");
kfree(buf);
return -ESRCH;
}
kfree(buf);
break;
case FIRMWARE_GET_VERSION:
/* get version */
if (copy_from_user(&cmd_info, argp, sizeof(cmd_info_t))) {
return -EFAULT;
}
mem_clear(version, FIRMWARE_NAME_LEN);
ret = fmw_cpld_upg_get_version(frm_dev->chain, cpld_info, version, FIRMWARE_NAME_LEN);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get version.\n");
return -ENXIO;
}
if (copy_to_user(cmd_info.data, version, cmd_info.size)) {
return -EFAULT;
}
break;
default:
FIRMWARE_DRIVER_DEBUG_ERROR("not find cmd: %d\r\n", cmd);
return -ENOTTY;
} /* End of switch */
return FIRMWARE_SUCCESS;
}
static int firmware_cpld_release(struct inode *inode, struct file *file)
{
return 0;
}
static const struct file_operations cpld_dev_fops = {
.owner = THIS_MODULE,
.llseek = firmware_cpld_llseek,
.read = firmware_cpld_read,
.write = firmware_cpld_write,
.unlocked_ioctl = firmware_cpld_ioctl,
.open = firmware_cpld_open,
.release = firmware_cpld_release,
};
static int of_firmware_upgrade_config_init(struct device *dev, firmware_cpld_t *cpld_info)
{
int ret;
char *name;
int i;
char buf[64];
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_upgrade_config_init\r\n");
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
mem_clear(cpld_info, sizeof(firmware_cpld_t));
ret = 0;
ret += of_property_read_string(dev->of_node, "type", (const char **)&name);
ret += of_property_read_u32(dev->of_node, "tdi", &cpld_info->tdi);
ret += of_property_read_u32(dev->of_node, "tck", &cpld_info->tck);
ret += of_property_read_u32(dev->of_node, "tms", &cpld_info->tms);
ret += of_property_read_u32(dev->of_node, "tdo", &cpld_info->tdo);
ret += of_property_read_u32(dev->of_node, "chain", &cpld_info->chain);
ret += of_property_read_u32(dev->of_node, "chip_index", &cpld_info->chip_index);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(cpld_info->type, name, sizeof(cpld_info->type) - 1);
ret = of_property_read_u32(dev->of_node, "tck_delay", &cpld_info->tck_delay);
if(ret != 0) {
cpld_info->tck_delay = 60;
}
cpld_info->gpio_en_info_num = 0;
/* Enable through GPIO */
for (i = 0; i < FIRMWARE_EN_INFO_MAX; i++) {
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_gpio_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &cpld_info->gpio_en_info[i].en_gpio);
if(ret != 0) {
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_level_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &cpld_info->gpio_en_info[i].en_level);
if(ret != 0) {
break;
}
cpld_info->gpio_en_info_num++;
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("type:%s, chain:%u, chip_index:%u, en_info_num:%u\n",
cpld_info->type, cpld_info->chain, cpld_info->chip_index, cpld_info->gpio_en_info_num);
FIRMWARE_DRIVER_DEBUG_VERBOSE("tdi:%u, tck:%u, tms:%u, tdo:%u tck_delay:%u.\n",
cpld_info->tdi, cpld_info->tck, cpld_info->tms, cpld_info->tdo, cpld_info->tck_delay);
return 0;
}
static int firmware_upgrade_config_init(struct device *dev, firmware_cpld_t *cpld_info)
{
int i;
firmware_upgrade_device_t *firmware_upgrade_device;
firmware_jtag_device_t jtag_upg_device;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_upgrade_config_init\r\n");
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
if (dev->platform_data == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("platform data config error.\n");
return -1;
}
firmware_upgrade_device = dev->platform_data;
jtag_upg_device = firmware_upgrade_device->upg_type.jtag;
mem_clear(cpld_info, sizeof(firmware_cpld_t));
strncpy(cpld_info->type, firmware_upgrade_device->type, sizeof(cpld_info->type) - 1);
cpld_info->tdi = jtag_upg_device.tdi;
cpld_info->tck = jtag_upg_device.tck;
cpld_info->tms = jtag_upg_device.tms;
cpld_info->tdo = jtag_upg_device.tdo;
cpld_info->chain = firmware_upgrade_device->chain;
cpld_info->chip_index = firmware_upgrade_device->chip_index;
if (jtag_upg_device.tck_delay == 0) {
cpld_info->tck_delay = 60;
FIRMWARE_DRIVER_DEBUG_VERBOSE("no config tck_delay, use default value:%u\n", cpld_info->tck_delay);
} else {
cpld_info->tck_delay = jtag_upg_device.tck_delay;
}
if (firmware_upgrade_device->en_gpio_num > FIRMWARE_EN_INFO_MAX) {
FIRMWARE_DRIVER_DEBUG_ERROR("The number of en_gpio_num:%u configurations exceeds the maximum limit:%u.\n",
firmware_upgrade_device->en_gpio_num, FIRMWARE_EN_INFO_MAX);
return -ENXIO;
}
cpld_info->gpio_en_info_num = firmware_upgrade_device->en_gpio_num;
/* Enable through GPIO */
for (i = 0; i < cpld_info->gpio_en_info_num; i++) {
cpld_info->gpio_en_info[i].en_gpio = firmware_upgrade_device->en_gpio[i];
cpld_info->gpio_en_info[i].en_level = firmware_upgrade_device->en_level[i];
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("type:%s, chain:%u, chip_index:%u, en_info_num:%u\n",
cpld_info->type, cpld_info->chain, cpld_info->chip_index, cpld_info->gpio_en_info_num);
FIRMWARE_DRIVER_DEBUG_VERBOSE("tdi:%u, tck:%u, tms:%u, tdo:%u tck_delay:%u.\n",
cpld_info->tdi, cpld_info->tck, cpld_info->tms, cpld_info->tdo, cpld_info->tck_delay);
return 0;
}
static int firmware_cpld_probe(struct platform_device *pdev)
{
int ret;
firmware_cpld_t *cpld_info;
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_cpld_probe\r\n");
/* Gets the information in the device tree */
cpld_info = devm_kzalloc(&pdev->dev, sizeof(firmware_cpld_t), GFP_KERNEL);
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc cpld device tree.\n");
return -EPERM;
}
if (pdev->dev.of_node) {
ret = of_firmware_upgrade_config_init(&pdev->dev, cpld_info);
} else {
ret = firmware_upgrade_config_init(&pdev->dev, cpld_info);
}
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("get config init from dts error.\n");
return -EPERM;
}
frm_dev = devm_kzalloc(&pdev->dev, sizeof(firmware_device_t), GFP_KERNEL);
if (frm_dev == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc firmware device.\n");
return -EPERM;
}
/* Based on the link number, determine the name of the device file */
frm_dev->chain = cpld_info->chain;
snprintf(frm_dev->name, FIRMWARE_NAME_LEN - 1, "firmware_cpld%d", frm_dev->chain);
strncpy(cpld_info->devname, frm_dev->name, strlen(frm_dev->name) + 1);
INIT_LIST_HEAD(&frm_dev->list);
frm_dev->dev.minor = MISC_DYNAMIC_MINOR;
frm_dev->dev.name = frm_dev->name;
frm_dev->dev.fops = &cpld_dev_fops;
frm_dev->priv = cpld_info;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Register cpld firmware chain:%d, name:%s.\n", frm_dev->chain, frm_dev->name);
ret = firmware_device_register(frm_dev);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to register firmware device.\n");
return -EPERM;
}
platform_set_drvdata(pdev, frm_dev);
return 0;
}
static int __exit firmware_cpld_remove(struct platform_device *pdev)
{
firmware_device_t *frm_dev;
frm_dev = (firmware_device_t *)platform_get_drvdata(pdev);
firmware_device_unregister(frm_dev);
platform_set_drvdata(pdev, NULL);
return 0;
}
static struct of_device_id cpld_match[] = {
{
.compatible = "firmware_cpld",
},
{},
};
static struct platform_driver cpld_driver = {
.driver = {
.name = "firmware_cpld",
.owner = THIS_MODULE,
.of_match_table = cpld_match,
},
.probe = firmware_cpld_probe,
.remove = firmware_cpld_remove,
};
static firmware_driver_t fmw_drv_cpld = {
.name = "firmware_cpld",
.drv = &cpld_driver,
};
int firmware_cpld_init(void)
{
int ret;
INIT_LIST_HEAD(&fmw_drv_cpld.list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("cpld upgrade driver register \n");
ret = firmware_driver_register(&fmw_drv_cpld);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("cpld upgrade driver register failed.\n");
return ret;
}
return 0;
}
void firmware_cpld_exit(void)
{
firmware_driver_unregister(&fmw_drv_cpld);
INIT_LIST_HEAD(&fmw_drv_cpld.list);
}

View File

@ -0,0 +1,82 @@
#ifndef __FIRMWARE_H__
#define __FIRMWARE_H__
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <asm/ioctl.h>
/* Debug switch level */
typedef enum {
FIRWMARE_VERBOSE,
FIRWMARE_WARN,
FIRWMARE_ERROR,
FIRWMARE_END,
} firmware_debug_level_t;
#define FIRMWARE_DRIVER_DEBUG_VERBOSE(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_VERBOSE)) { \
printk(KERN_INFO "[FIRMWARW_DRIVER_CPLD][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_DRIVER_DEBUG_ERROR(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_ERROR)) { \
printk(KERN_ERR "[FIRMWARW_DRIVER_CPLD][ERR][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_NAME_LEN 48
#define FIRMWARE_FAILED (-1)
#define FIRMWARE_SUCCESS 0
/* ioctl publi command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_COMMON_TYPE 'C'
#define FIRMWARE_GET_CHIPNAME _IOR(FIRMWARE_COMMON_TYPE, 0, char) /* get the chip name */
#define FIRMWARE_GET_VERSION _IOR(FIRMWARE_COMMON_TYPE, 2, int) /* get version */
/* firmware cpld driver ioctl command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_TYPE 'J'
#define FIRMWARE_PROGRAM _IOW(FIRMWARE_TYPE, 1, char) /* firmware upgrade ISC */
#define FIRMWARE_READ_CHIP _IOR(FIRMWARE_TYPE, 5, int) /* read the contents of the chip */
#define FIRMWARE_PROGRAM_JBI _IOW(FIRMWARE_TYPE, 6, char) /* firmware upgrade JBI */
typedef struct cmd_info_s {
uint32_t size;
void __user *data;
} cmd_info_t;
typedef struct firmware_device_s {
struct list_head list; /* device list */
uint32_t chain; /* chain number */
char name[FIRMWARE_NAME_LEN]; /* name */
struct miscdevice dev; /* device */
void *priv; /* private data */
} firmware_device_t;
typedef struct firmware_driver_s {
struct list_head list; /* list */
char name[FIRMWARE_NAME_LEN]; /* name */
struct platform_driver *drv; /* driver */
void *priv; /* private data */
} firmware_driver_t;
extern int g_firmware_driver_debug;
/* Get device information based on minor */
extern firmware_device_t *firmware_get_device_by_minor(int minor);
/* Registere device */
extern int firmware_device_register(firmware_device_t *fw_dev);
/* Unregister device */
extern void firmware_device_unregister(firmware_device_t *fw_dev);
/* Registere driver */
extern int firmware_driver_register(firmware_driver_t *fw_drv);
/* Unregister driver */
extern void firmware_driver_unregister(firmware_driver_t *fw_drv);
/* CPLD upgrade initialized */
extern int firmware_cpld_init(void);
/* CPLD unload function */
extern void firmware_cpld_exit(void);
#endif /* end of __FIRMWARE_H__ */

View File

@ -0,0 +1,64 @@
#ifndef __FIRMWARE_CPLD_H__
#define __FIRMWARE_CPLD_H__
#define FIRMWARE_DEV_NAME_LEN 32
#define FIRMWARE_MAX_CPLD_NUM 16
#define FIRMWARE_TYPE_LEN 10
#define FIRMWARE_EN_INFO_MAX 16
#define FIRMWARE_EN_INFO_BUF 128
typedef struct firmware_gpio_jtag_en_s {
uint32_t en_gpio; /* GPIO enable pin */
uint32_t en_level; /* GPIO enable level */
int flag; /* init flag; 1-init 0-not init */
} firmware_gpio_jtag_en_t;
typedef struct firmware_cpld_s {
char devname[FIRMWARE_DEV_NAME_LEN]; /* Device name */
char type[FIRMWARE_TYPE_LEN]; /* interface type */
uint32_t tdi; /* TDI signal corresponding to GPIO pin information */
uint32_t tck; /* TCK signal corresponding to GPIO pin information */
uint32_t tms; /* TMS signal corresponding to GPIO pin information */
uint32_t tdo; /* TDO signal corresponding to GPIO pin information */
uint32_t chain; /* chain num */
uint32_t chip_index; /* chip index */
uint32_t tck_delay; /* Delay time */
uint32_t gpio_en_info_num; /* GPIO Enable Number */
firmware_gpio_jtag_en_t gpio_en_info[FIRMWARE_EN_INFO_MAX]; /* GPIO Enable Information */
} firmware_cpld_t;
typedef struct firmware_cpld_function_s{
int (*pull_tdi_up)(void); /* TDI pull-up */
int (*pull_tdi_down)(void); /* TDI pull-down */
int (*pull_tck_up)(void); /* TCK pull-up */
int (*pull_tck_down)(void); /* TCK pull-down */
int (*pull_tms_up)(void); /* TMS pull-up */
int (*pull_tms_down)(void); /* TCK pull-down */
int (*read_tdo)(void); /* Read TDO */
int (*init_cpld)(void); /* CPLD upgrade initializes the operation */
int (*init_chip)(int chain); /* chip initializes the operation */
int (*finish_chip)(int chain); /* chip completes the operation*/
int (*finish_cpld)(void); /* CPLD upgrade completes the operation */
int (*get_version)(int chain, char *ver, int len); /* get version */
}firmware_cpld_function_t;
/* get chip name */
extern int fmw_cpld_upg_get_chip_name(int chain, firmware_cpld_t *cpld, char *info, int len);
/* ISC firmware upgrad */
extern int fmw_cpld_upg_program(int chain, firmware_cpld_t *cpld, char *info, int len);
/* get version */
extern int fmw_cpld_upg_get_version(int chain, firmware_cpld_t *cpld, char *info, int len);
/* Read the contents of Chip */
extern int fmw_cpld_upg_get_chip_info(int chain, firmware_cpld_t *cpld, void *info, int len);
/* operate TDI */
extern int fwm_cpld_tdi_op(int value);
/* operate TCK */
extern int fwm_cpld_tck_op(int value);
/* operate TMS */
extern int fwm_cpld_tms_op(int value);
/* operate TDO */
extern int fwm_cpld_tdo_op(void);
/* JBI firmware upgrad */
extern int fmw_cpld_upg_program_jbi(int chain, firmware_cpld_t *cpld, char *info, int len);
#endif /* __FIRMWARE_CPLD_H__ */

View File

@ -0,0 +1,15 @@
#ifndef __JBI_H__
#define __JBI_H__
#include <linux/types.h>
/* JTAG operation interface*/
extern int jbi_jtag_io_(int tms, int tdi, int read_tdo);
/* delay function */
extern void jbi_jtag_udelay(unsigned long us);
/* Debug switch */
extern int jbi_debug(int level);
/* JBI upgrade function */
extern int jbi_main(unsigned char *addr, unsigned long size, int argc, char * const argv[]);
#endif /* __JBI_JTAG_H__ */

View File

@ -0,0 +1,438 @@
/****************************************************************************/
/* */
/* Module: jbicomp.c */
/* */
/* Copyright (C) Altera Corporation 1997-2001 */
/* */
/* Description: Contains the code for compressing and uncompressing */
/* Boolean array data. */
/* */
/* This algorithm works by searching previous bytes in the */
/* data that match the current data. If a match is found, */
/* then the offset and length of the matching data can */
/* replace the actual data in the output. */
/* */
/* Revisions: 2.2 fixed /W4 warnings */
/* */
/****************************************************************************/
#include "jbiport.h"
#include "jbiexprt.h"
#include "jbicomp.h"
#include "jbistub.h"
#define SHORT_BITS 16
#define CHAR_BITS 8
#define DATA_BLOB_LENGTH 3
#define MATCH_DATA_LENGTH 8192
#define JBI_ACA_REQUEST_SIZE 1024
#define JBI_ACA_BUFFER_SIZE (MATCH_DATA_LENGTH + JBI_ACA_REQUEST_SIZE)
unsigned long jbi_in_length = 0L;
unsigned long jbi_in_index = 0L; /* byte index into compressed array */
unsigned int jbi_bits_avail = CHAR_BITS;
#if PORT == DOS
int jbi_current_variable_id = -1;
int jbi_current_page = -1;
int jbi_version = 0;
unsigned long jbi_out_length = 0L;
unsigned int jbi_out_index = 0; /* byte index into jbi_aca_out_buffer[] */
unsigned long jbi_aca_in_offset = 0L;
unsigned char jbi_aca_out_buffer[JBI_ACA_BUFFER_SIZE];
#endif
/****************************************************************************/
/* */
/* The following functions implement incremental decompression of Boolean */
/* array data, using a small memory window. */
/* */
/* This algorithm works by searching previous bytes in the data that match */
/* the current data. If a match is found, then the offset and length of */
/* the matching data can replace the actual data in the output. */
/* */
/* Memory usage is reduced by maintaining a "window" buffer which contains */
/* the uncompressed data for one 8K page, plus some extra amount specified */
/* by JBI_ACA_REQUEST_SIZE. The function jbi_uncompress_page() is used to */
/* request a subrange of the uncompressed data, starting at a particular */
/* bit position and extending a maximum of JBI_ACA_REQUEST_SIZE bytes. */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
unsigned int jbi_bits_required(unsigned int n)
/* */
/* Description: Calculate the minimum number of bits required to */
/* represent n. */
/* */
/* Returns: Number of bits. */
/* */
/****************************************************************************/
{
unsigned int result = SHORT_BITS;
if (n == 0)
{
result = 1;
}
else
{
/* Look for the highest non-zero bit position */
while ((n & (1 << (SHORT_BITS - 1))) == 0)
{
n <<= 1;
--result;
}
}
return (result);
}
/****************************************************************************/
/* */
unsigned int jbi_read_packed
(
#if PORT!=DOS
unsigned char *buffer,
#endif
unsigned int bits
)
/* */
/* Description: Read the next value from the input array "buffer". */
/* Read only "bits" bits from the array. The amount of */
/* bits that have already been read from "buffer" is */
/* stored internally to this function. */
/* */
/* Returns: Up to 16 bit value. -1 if buffer overrun. */
/* */
/****************************************************************************/
{
unsigned int result = 0;
unsigned int shift = 0;
unsigned int databyte = 0;
while (bits > 0)
{
#if PORT==DOS
databyte = GET_BYTE(jbi_aca_in_offset + jbi_in_index);
#else
databyte = buffer[jbi_in_index];
#endif
result |= (((databyte >> (CHAR_BITS - jbi_bits_avail))
& (0xFF >> (CHAR_BITS - jbi_bits_avail))) << shift);
if (bits <= jbi_bits_avail)
{
result &= (0xFFFF >> (SHORT_BITS - (bits + shift)));
jbi_bits_avail -= bits;
bits = 0;
}
else
{
++jbi_in_index;
shift += jbi_bits_avail;
bits -= jbi_bits_avail;
jbi_bits_avail = CHAR_BITS;
}
}
return (result);
}
#if PORT==DOS
/****************************************************************************/
/* */
void jbi_uncompress_next_page(int version)
/* */
/* Description: Uncompresses one page of compressed data, using */
/* data page as reference for repeated sections. */
/* Overwrites previous page of data in buffer. */
/* */
/* Returns: TRUE for success, FALSE if error encountered */
/* */
/****************************************************************************/
{
unsigned int i, j, offset, length;
unsigned int end_index;
unsigned long tmp_in_index = jbi_in_index;
unsigned int tmp_out_index = jbi_out_index;
unsigned int tmp_bits_avail = jbi_bits_avail;
unsigned int prev[3];
unsigned long long_end;
unsigned int match_data_length = MATCH_DATA_LENGTH;
if (version > 0) --match_data_length;
if (jbi_current_page < 0)
{
/* this is the first page of the array */
jbi_current_page = 0;
jbi_in_index = 4; /* skip over length field */
jbi_out_index = 0;
end_index = (jbi_out_length < JBI_ACA_BUFFER_SIZE) ?
(unsigned int) jbi_out_length : JBI_ACA_BUFFER_SIZE;
}
else
{
/* this is not the first page */
++jbi_current_page;
jbi_out_index -= MATCH_DATA_LENGTH;
long_end = jbi_out_length -
((long) jbi_current_page * (long) MATCH_DATA_LENGTH);
end_index = (long_end < JBI_ACA_BUFFER_SIZE) ?
(unsigned int) long_end : JBI_ACA_BUFFER_SIZE;
/* copy extra data from end of circular buffer to beginning */
for (i = 0; i < jbi_out_index; ++i)
{
jbi_aca_out_buffer[i] = jbi_aca_out_buffer[i + MATCH_DATA_LENGTH];
}
}
while (jbi_out_index < end_index)
{
/* save state so we can undo the last packet when we reach the end */
tmp_in_index = jbi_in_index;
tmp_out_index = jbi_out_index;
tmp_bits_avail = jbi_bits_avail;
/* A 0 bit indicates literal data. */
if (jbi_read_packed(1) == 0)
{
for (i = 0; i < DATA_BLOB_LENGTH; ++i)
{
if (jbi_out_index < end_index)
{
if (version == 0)
{
prev[i] = jbi_aca_out_buffer[jbi_out_index] & 0xff;
}
jbi_aca_out_buffer[jbi_out_index++] =
(unsigned char) jbi_read_packed(CHAR_BITS);
}
}
}
else
{
/* A 1 bit indicates offset/length to follow. */
offset = jbi_read_packed(jbi_bits_required(
(jbi_current_page > 0) ? match_data_length :
(jbi_out_index > match_data_length ? match_data_length :
jbi_out_index)));
length = jbi_read_packed(CHAR_BITS);
if ((version == 0) && (offset == match_data_length + 3))
{
jbi_aca_out_buffer[jbi_out_index++] = (unsigned char) prev[0];
jbi_aca_out_buffer[jbi_out_index++] = (unsigned char) prev[1];
jbi_aca_out_buffer[jbi_out_index++] = (unsigned char) prev[2];
length -= 3;
}
for (i = 0; i < length; ++i)
{
if (jbi_out_index < end_index)
{
if (offset > jbi_out_index)
{
j = jbi_out_index + MATCH_DATA_LENGTH - offset;
}
else j = jbi_out_index - offset;
jbi_aca_out_buffer[jbi_out_index] = jbi_aca_out_buffer[j];
++jbi_out_index;
}
}
if (version == 0)
{
prev[0] = jbi_aca_out_buffer[jbi_out_index - 3] & 0xff;
prev[1] = jbi_aca_out_buffer[jbi_out_index - 2] & 0xff;
prev[2] = jbi_aca_out_buffer[jbi_out_index - 1] & 0xff;
}
}
}
/* restore the state before the previous packet */
jbi_in_index = tmp_in_index;
jbi_out_index = tmp_out_index;
jbi_bits_avail = tmp_bits_avail;
}
/****************************************************************************/
/* */
void jbi_uncompress_page
(
int variable_id,
int page,
int version
)
/* */
/* Description: Uncompress requested page of variable data. Stores */
/* uncompressed data in jbi_aca_out_buffer[]. */
/* */
/* Returns: TRUE if successful, otherwise FALSE if: */
/* 1) variable is not a compressed array */
/* 2) compressed data is illegal or corrupted */
/* 3) requested page is beyond the end of the array */
/* 4) internal error in the code */
/* */
/****************************************************************************/
{
unsigned long symbol_table;
unsigned long data_section;
unsigned long offset;
unsigned long value;
int delta = version * 2;
if (variable_id != jbi_current_variable_id)
{
/* initialize to uncompress the desired variable */
symbol_table = GET_DWORD(16 + (version * 8));
data_section = GET_DWORD(20 + (version * 8));
offset = symbol_table + ((11 + delta) * variable_id);
value = GET_DWORD(offset + 3 + delta);
jbi_current_variable_id = variable_id;
jbi_current_page = -1;
jbi_bits_avail = CHAR_BITS;
jbi_in_length = GET_DWORD(offset + 7 + delta);
jbi_out_length =
(((unsigned long) GET_BYTE(data_section + value)) |
(((unsigned long) GET_BYTE(data_section + value + 1)) << 8) |
(((unsigned long) GET_BYTE(data_section + value + 2)) << 16) |
(((unsigned long) GET_BYTE(data_section + value + 3)) << 24));
jbi_in_index = 4; /* skip over length field */
jbi_out_index = 0;
jbi_aca_in_offset = data_section + value;
}
/* to look back at an earlier page, start over at the beginning */
if (page < jbi_current_page)
{
jbi_current_page = -1;
jbi_in_index = 4; /* skip over length field */
jbi_bits_avail = CHAR_BITS;
}
/* uncompress sequentially up to the desired page */
while (page > jbi_current_page)
{
jbi_uncompress_next_page(version);
}
}
#else
/****************************************************************************/
/* */
unsigned long jbi_uncompress
(
unsigned char *in,
unsigned long in_length,
unsigned char *out,
unsigned long out_length,
int version
)
/* */
/* Description: Uncompress data in "in" and write result to "out". */
/* */
/* Returns: Length of uncompressed data. -1 if: */
/* 1) out_length is too small */
/* 2) Internal error in the code */
/* 3) in doesn't contain ACA compressed data. */
/* */
/****************************************************************************/
{
#ifdef CONFIG_64BIT
unsigned int data_length = 0;
#else
unsigned long data_length = 0L;
#endif
unsigned long i, j;
unsigned int offset, length;
unsigned int match_data_length = MATCH_DATA_LENGTH;
if (version > 0) --match_data_length;
jbi_in_length = in_length;
jbi_bits_avail = CHAR_BITS;
jbi_in_index = 0L;
for (i = 0; i < out_length; ++i) out[i] = 0;
/* Read number of bytes in data. */
#ifdef CONFIG_64BIT
for (i = 0; i < sizeof(unsigned int); ++i)
{
data_length = data_length | ((unsigned int)
jbi_read_packed(in, CHAR_BITS) << (i * CHAR_BITS));
}
#else
for (i = 0; i < sizeof (in_length); ++i)
{
data_length = data_length | ((unsigned long)
jbi_read_packed(in, CHAR_BITS) << (i * CHAR_BITS));
}
#endif
if (data_length > out_length)
{
#ifdef CONFIG_64BIT
jbi_dbg(DEBUG_ERR, "data_length(0x%x,0x%lx)\n",
data_length, out_length);
data_length = 0;
#else
jbi_dbg(DEBUG_ERR, "data_length(0x%lx,0x%lx)\n",
data_length, out_length);
data_length = 0L;
#endif
}
else
{
i = 0;
while (i < data_length)
{
/* A 0 bit indicates literal data. */
if (jbi_read_packed(in, 1) == 0)
{
for (j = 0; j < DATA_BLOB_LENGTH; ++j)
{
if (i < data_length)
{
out[i] = (unsigned char) jbi_read_packed(in, CHAR_BITS);
i++;
}
}
}
else
{
/* A 1 bit indicates offset/length to follow. */
offset = jbi_read_packed(in, jbi_bits_required((short) (i > match_data_length ? match_data_length : i)));
length = jbi_read_packed(in, CHAR_BITS);
for (j = 0; j < length; ++j)
{
if (i < data_length)
{
out[i] = out[i - offset];
i++;
}
}
}
}
}
return (data_length);
}
#endif

View File

@ -0,0 +1,37 @@
/****************************************************************************/
/* */
/* Module: jbicomp.h */
/* */
/* Copyright (C) Altera Corporation 1997-2001 */
/* */
/* Description: Contains the function prototypes for compressing */
/* and uncompressing Boolean array data. */
/* */
/****************************************************************************/
#ifndef INC_JBICOMP_H
#define INC_JBICOMP_H
#if PORT==DOS
void jbi_uncompress_page
(
int variable_id,
int page,
int version
);
#else
unsigned long jbi_uncompress
(
unsigned char *in,
unsigned long in_length,
unsigned char *out,
unsigned long out_length,
int version
);
#endif /* PORT==DOS */
#endif /* INC_JBICOMP_H */

View File

@ -0,0 +1,224 @@
/****************************************************************************/
/* */
/* Module: jbiexprt.h */
/* */
/* Copyright (C) Altera Corporation 1998-2001 */
/* */
/* Description: Jam STAPL ByteCode Player Export Header File */
/* */
/* Revisions: */
/* */
/****************************************************************************/
#ifndef INC_JBIEXPRT_H
#define INC_JBIEXPRT_H
/****************************************************************************/
/* */
/* Return codes from most JBI functions */
/* */
/****************************************************************************/
#define JBI_RETURN_TYPE int
#define JBIC_SUCCESS 0
#define JBIC_OUT_OF_MEMORY 1
#define JBIC_IO_ERROR 2
/* #define JAMC_SYNTAX_ERROR 3 */
#define JBIC_UNEXPECTED_END 4
#define JBIC_UNDEFINED_SYMBOL 5
/* #define JAMC_REDEFINED_SYMBOL 6 */
#define JBIC_INTEGER_OVERFLOW 7
#define JBIC_DIVIDE_BY_ZERO 8
#define JBIC_CRC_ERROR 9
#define JBIC_INTERNAL_ERROR 10
#define JBIC_BOUNDS_ERROR 11
/* #define JAMC_TYPE_MISMATCH 12 */
/* #define JAMC_ASSIGN_TO_CONST 13 */
/* #define JAMC_NEXT_UNEXPECTED 14 */
/* #define JAMC_POP_UNEXPECTED 15 */
/* #define JAMC_RETURN_UNEXPECTED 16 */
/* #define JAMC_ILLEGAL_SYMBOL 17 */
#define JBIC_VECTOR_MAP_FAILED 18
#define JBIC_USER_ABORT 19
#define JBIC_STACK_OVERFLOW 20
#define JBIC_ILLEGAL_OPCODE 21
/* #define JAMC_PHASE_ERROR 22 */
/* #define JAMC_SCOPE_ERROR 23 */
#define JBIC_ACTION_NOT_FOUND 24
/****************************************************************************/
/* */
/* Macro Definitions */
/* */
/****************************************************************************/
/*
* For DOS port, program data is stored in a set of 16K pages, accessed
* through a pointer table. For 32-bit version, the buffer is continuous.
* The macro GET_BYTE gets a single byte for either case.
*/
#if PORT==DOS
#define PROGRAM_PTR unsigned char **
#else
#define PROGRAM_PTR unsigned char *
#endif
#if PORT==DOS
#define GET_BYTE(x) (jbi_program[(x) >> 14L][(x) & 0x3fffL])
#else
#define GET_BYTE(x) (program[x])
#endif
#define GET_WORD(x) \
(((((unsigned short) GET_BYTE(x)) << 8) & 0xFF00) | \
(((unsigned short) GET_BYTE((x)+1)) & 0x00FF))
#define GET_DWORD(x) \
(((((unsigned long) GET_BYTE(x)) << 24L) & 0xFF000000L) | \
((((unsigned long) GET_BYTE((x)+1)) << 16L) & 0x00FF0000L) | \
((((unsigned long) GET_BYTE((x)+2)) << 8L) & 0x0000FF00L) | \
(((unsigned long) GET_BYTE((x)+3)) & 0x000000FFL))
/****************************************************************************/
/* */
/* Structured Types */
/* */
/****************************************************************************/
typedef struct JBI_PROCINFO_STRUCT
{
char *name;
unsigned char attributes;
struct JBI_PROCINFO_STRUCT *next;
}
JBI_PROCINFO;
/****************************************************************************/
/* */
/* Global Data Prototypes */
/* */
/****************************************************************************/
#if PORT==DOS
extern unsigned char jbi_aca_out_buffer[8192 + 1024];
#endif
extern PROGRAM_PTR jbi_program;
extern char *jbi_workspace;
extern long jbi_workspace_size;
/****************************************************************************/
/* */
/* Function Prototypes */
/* */
/****************************************************************************/
JBI_RETURN_TYPE jbi_execute
(
PROGRAM_PTR program,
long program_size,
char *workspace,
long workspace_size,
char *action,
char **init_list,
int reset_jtag,
long *error_address,
int *exit_code,
int *format_version
);
JBI_RETURN_TYPE jbi_get_note
(
PROGRAM_PTR program,
long program_size,
long *offset,
char *key,
char *value,
int length
);
JBI_RETURN_TYPE jbi_check_crc
(
PROGRAM_PTR program,
long program_size,
unsigned short *expected_crc,
unsigned short *actual_crc
);
JBI_RETURN_TYPE jbi_get_file_info
(
PROGRAM_PTR program,
long program_size,
int *format_version,
int *action_count,
int *procedure_count
);
JBI_RETURN_TYPE jbi_get_action_info
(
PROGRAM_PTR program,
long program_size,
int index,
char **name,
char **description,
JBI_PROCINFO **procedure_list
);
int jbi_jtag_io
(
int tms,
int tdi,
int read_tdo
);
void jbi_message
(
char *message_text
);
void jbi_export_integer
(
char *key,
long value
);
void jbi_export_boolean_array
(
char *key,
unsigned char *data,
long count
);
void jbi_delay
(
long microseconds
);
int jbi_vector_map
(
int signal_count,
char **signals
);
int jbi_vector_io
(
int signal_count,
long *dir_vect,
long *data_vect,
long *capture_vect
);
void *jbi_malloc
(
unsigned int size
);
void jbi_free
(
void *ptr
);
#endif /* INC_JBIEXPRT_H */

View File

@ -0,0 +1,146 @@
/****************************************************************************/
/* */
/* Module: jbijtag.h */
/* */
/* Copyright (C) Altera Corporation 1998-2001 */
/* */
/* Description: Definitions of JTAG constants, types, and functions */
/* */
/****************************************************************************/
#ifndef INC_JBIJTAG_H
#define INC_JBIJTAG_H
/****************************************************************************/
/* */
/* Function Prototypes */
/* */
/****************************************************************************/
typedef enum
{
JBI_ILLEGAL_JTAG_STATE = -1,
RESET = 0,
IDLE = 1,
DRSELECT = 2,
DRCAPTURE = 3,
DRSHIFT = 4,
DREXIT1 = 5,
DRPAUSE = 6,
DREXIT2 = 7,
DRUPDATE = 8,
IRSELECT = 9,
IRCAPTURE = 10,
IRSHIFT = 11,
IREXIT1 = 12,
IRPAUSE = 13,
IREXIT2 = 14,
IRUPDATE = 15
} JBIE_JTAG_STATE;
JBI_RETURN_TYPE jbi_init_jtag
(
void
);
JBI_RETURN_TYPE jbi_set_drstop_state
(
JBIE_JTAG_STATE state
);
JBI_RETURN_TYPE jbi_set_irstop_state
(
JBIE_JTAG_STATE state
);
JBI_RETURN_TYPE jbi_set_dr_preamble
(
unsigned int count,
unsigned int start_index,
unsigned char *preamble_data
);
JBI_RETURN_TYPE jbi_set_ir_preamble
(
unsigned int count,
unsigned int start_index,
unsigned char *preamble_data
);
JBI_RETURN_TYPE jbi_set_dr_postamble
(
unsigned int count,
unsigned int start_index,
unsigned char *postamble_data
);
JBI_RETURN_TYPE jbi_set_ir_postamble
(
unsigned int count,
unsigned int start_index,
unsigned char *postamble_data
);
JBI_RETURN_TYPE jbi_goto_jtag_state
(
JBIE_JTAG_STATE state
);
JBI_RETURN_TYPE jbi_do_wait_cycles
(
long cycles,
JBIE_JTAG_STATE wait_state
);
JBI_RETURN_TYPE jbi_do_wait_microseconds
(
long microseconds,
JBIE_JTAG_STATE wait_state
);
JBI_RETURN_TYPE jbi_do_irscan
(
unsigned int count,
unsigned char *tdi_data,
unsigned int start_index
);
JBI_RETURN_TYPE jbi_swap_ir
(
unsigned int count,
unsigned char *in_data,
unsigned int in_index,
unsigned char *out_data,
unsigned int out_index
);
JBI_RETURN_TYPE jbi_do_drscan
(
unsigned int count,
unsigned char *tdi_data,
unsigned long start_index
);
JBI_RETURN_TYPE jbi_swap_dr
(
unsigned int count,
unsigned char *in_data,
unsigned long in_index,
unsigned char *out_data,
unsigned int out_index
);
void jbi_free_jtag_padding_buffers
(
int reset_jtag
);
JBI_RETURN_TYPE jbi_do_drscan_multi_page
(
unsigned int variable_id,
unsigned long long_count,
unsigned long long_index,
int version
);
#endif /* INC_JBIJTAG_H */

View File

@ -0,0 +1,45 @@
/****************************************************************************/
/* */
/* Module: jbiport.h */
/* */
/* Copyright (C) Altera Corporation 2000-2001 */
/* */
/* Description: Defines porting macros */
/* */
/****************************************************************************/
#ifndef INC_JBIPORT_H
#define INC_JBIPORT_H
/*
* PORT defines the target platform: DOS, WINDOWS, UNIX, or EMBEDDED
*
* PORT = DOS means a 16-bit DOS console-mode application
*
* PORT = WINDOWS means a 32-bit WIN32 console-mode application for
* Windows 95, 98, 2000, ME or NT. On NT this will use the
* DeviceIoControl() API to access the Parallel Port.
*
* PORT = UNIX means any UNIX system. BitBlaster access is support via
* the standard ANSI system calls open(), read(), write().
* The ByteBlaster is not supported.
*
* PORT = EMBEDDED means all DOS, WINDOWS, and UNIX code is excluded.
* Remaining code supports 16 and 32-bit compilers.
* Additional porting steps may be necessary. See readme
* file for more details.
*/
#define DOS 2
#define WINDOWS 3
#define UNIX 4
#define EMBEDDED 5
#define PORT EMBEDDED
#ifndef PORT
/* change this line to build a different port */
#define PORT WINDOWS
#endif
#endif /* INC_JBIPORT_H */

View File

@ -0,0 +1,95 @@
#ifndef __JBISTUB_H__
#define __JBISTUB_H__
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/kernel.h>
#include <linux/gfp.h>
#include <linux/mm.h>
#include <linux/delay.h>
#include <linux/slab.h>
#ifdef CONFIG_64BIT
typedef s64 addr_t;
#else
typedef s32 addr_t;
#endif
/* typedef long addr_t; */
/* #define USE_STATIC_MEMORY 100 */
/* #define MEM_TRACKER */
/* #define O_RDWR 1 */
#define stdout (1)
#define stderr (2)
#define puts printk
#define printf printk
#define fprintf(std, fmt, arg...) \
do { \
printf(fmt, ##arg); \
} while (0)
#define DEBUG_NONE 0
#define DEBUG_ERR 1
#define DEBUG_DETAIL 2
#define DEBUG_NOISY 3
#define DEBUG_MM 4
#define jbi_dbg(level, fmt, arg...) \
do { \
if (level <= jbi_debug_level) { \
printf(fmt, ##arg); \
} \
} while (0)
extern int jbi_debug_level;
static inline int open(char *path, int flag)
{
return 0;
}
static inline int close(int fd)
{
return 0;
}
static inline int read(int fd, char *buf, int count)
{
return 0;
}
static inline int write(int fd, char *buf, int count)
{
return 0;
}
static inline int fflush(int fd)
{
return 0;
}
static inline int clock(void)
{
return 0;
}
static inline int atoi(const char *nptr)
{
return (int) simple_strtol(nptr, (char **) NULL, 10);
}
static inline void *malloc(size_t size)
{
return kmalloc(size, GFP_KERNEL);
}
static inline void free(void *ptr)
{
kfree(ptr);
}
#endif /* __JBISTUB_H__ */

View File

@ -0,0 +1,22 @@
#include $(top_srcdir)/debian/rules
#KERNELDIR := ${KBUILD_OUTPUT}
PWD = $(shell pwd)
EXTRA_CFLAGS:= -I$(M)/include
MAKEFILE_FILE_PATH = $(abspath $(lastword $(MAKEFILE_LIST)))
FIRMWARE_UPGRADE_PATH = $(abspath $(MAKEFILE_FILE_PATH)/../../include)
EXTRA_CFLAGS+= -I$(FIRMWARE_UPGRADE_PATH)
EXTRA_CFLAGS+= -Wall
firmware_driver_ispvme-objs := firmware_ispvme.o
firmware_driver_ispvme-objs += firmware_cpld_ispvme.o firmware_cpld_upgrade_ispvme.o
#ifndef CONFIG_FRM_PRODUCT_FILE
$(warning $(firmware_driver_ispvme-objs))
obj-m := firmware_driver_ispvme.o
all:
$(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules
@if [ ! -d $(common_module_dir) ]; then mkdir -p $(common_module_dir) ;fi
cp -p $(PWD)/*.ko $(common_module_dir)

View File

@ -0,0 +1,450 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/of.h>
#include <linux/uaccess.h>
#include <firmware_ispvme.h>
#include <firmware_cpld_ispvme.h>
#include <firmware_upgrade.h>
static int firmware_cpld_open(struct inode *inode, struct file *file)
{
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Open cpld device.\n");
frm_dev = firmware_get_device_by_minor(MINOR(inode->i_rdev));
if (frm_dev == NULL) {
return -ENXIO;
}
file->private_data = frm_dev;
return FIRMWARE_SUCCESS;
}
static ssize_t firmware_cpld_read (struct file *file, char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static ssize_t firmware_cpld_write (struct file *file, const char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static loff_t firmware_cpld_llseek(struct file *file, loff_t offset, int origin)
{
return 0;
}
/*
* firmware_cpld_ioctl
* function: ispvme driver ioctl command parsing function
* @file: param[in] device file name
* @cmd: param[in] command
* @arg: param[in] the parameters in the command
* return value: success-FIRMWARE_SUCCESS; fail:other value
*/
static long firmware_cpld_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;
void __user *argp;
firmware_device_t *frm_dev;
firmware_cpld_t *cpld_info;
char value;
/* Get device private data */
frm_dev = (firmware_device_t *)file->private_data;
cpld_info = NULL;
if (frm_dev != NULL) {
if (frm_dev->priv != NULL) {
cpld_info = (firmware_cpld_t *)frm_dev->priv;
}
}
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to frm_dev->priv sysfs info.\n");
return FIRMWARE_FAILED;
}
argp = (void __user *)arg;
switch (cmd) {
case FIRMWARE_JTAG_TDI:
/* Set the TDI signal */
if (copy_from_user(&value, argp, sizeof(value))) {
return -EFAULT;
}
if (fwm_cpld_tdi_op(value) < 0 ) {
return -EFAULT;
}
break;
case FIRMWARE_JTAG_TCK:
/* Set the TCK signal */
if (copy_from_user(&value, argp, sizeof(value))) {
return -EFAULT;
}
if (fwm_cpld_tck_op(value) < 0) {
return -EFAULT;
}
break;
case FIRMWARE_JTAG_TMS:
/* Set the TMS signal */
if (copy_from_user(&value, argp, sizeof(value))) {
return -EFAULT;
}
if (fwm_cpld_tms_op(value) < 0) {
return -EFAULT;
}
break;
case FIRMWARE_JTAG_TDO:
/* Read the TDO signal */
value = fwm_cpld_tdo_op();
if (copy_to_user(argp, &value, sizeof(value))) {
return -EFAULT;
}
break;
case FIRMWARE_JTAG_INIT:
/* The VME upgrade mode initializes the operation */
ret=firmware_init_vme(cpld_info);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to init upgrade.(chain = %d)\n",
frm_dev != NULL ? frm_dev->chain : -1);
return FIRMWARE_FAILED;
}
break;
case FIRMWARE_JTAG_FINISH:
/* The VME upgrade mode completes the operation */
ret=firmware_finish_vme(cpld_info);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to release upgrade.(chain = %d)\n",
frm_dev != NULL ? frm_dev->chain : -1);
return FIRMWARE_FAILED;
}
break;
default:
FIRMWARE_DRIVER_DEBUG_ERROR("not find cmd: %d\r\n", cmd);
return -ENOTTY;
} /* End of switch */
return FIRMWARE_SUCCESS;
}
static int firmware_cpld_release(struct inode *inode, struct file *file)
{
return 0;
}
static const struct file_operations cpld_dev_fops = {
.owner = THIS_MODULE,
.llseek = firmware_cpld_llseek,
.read = firmware_cpld_read,
.write = firmware_cpld_write,
.unlocked_ioctl = firmware_cpld_ioctl,
.open = firmware_cpld_open,
.release = firmware_cpld_release,
};
static int of_firmware_upgrade_config_init(struct device *dev, firmware_cpld_t *cpld_info)
{
int ret;
char *name;
int i;
char buf[64];
firmware_logic_dev_en_t *firmware_logic_dev_en_point;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_upgrade_config_init\r\n");
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
mem_clear(cpld_info, sizeof(firmware_cpld_t));
ret = 0;
ret += of_property_read_string(dev->of_node, "type", (const char **)&name);
ret += of_property_read_u32(dev->of_node, "tdi", &cpld_info->tdi);
ret += of_property_read_u32(dev->of_node, "tck", &cpld_info->tck);
ret += of_property_read_u32(dev->of_node, "tms", &cpld_info->tms);
ret += of_property_read_u32(dev->of_node, "tdo", &cpld_info->tdo);
ret += of_property_read_u32(dev->of_node, "chain", &cpld_info->chain);
ret += of_property_read_u32(dev->of_node, "chip_index", &cpld_info->chip_index);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(cpld_info->type, name, sizeof(cpld_info->type) - 1);
ret = of_property_read_u32(dev->of_node, "tck_delay", &cpld_info->tck_delay);
if(ret != 0) {
cpld_info->tck_delay = 60;
}
cpld_info->gpio_en_info_num = 0;
/* Enable through GPIO */
for (i = 0; i < FIRMWARE_EN_INFO_MAX; i++) {
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_gpio_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &cpld_info->gpio_en_info[i].en_gpio);
if(ret != 0) {
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_level_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &cpld_info->gpio_en_info[i].en_level);
if(ret != 0) {
break;
}
cpld_info->gpio_en_info_num++;
}
cpld_info->logic_dev_en_num = 0;
/* Enable through register */
for (i = 0; i < FIRMWARE_EN_INFO_MAX; i++) {
firmware_logic_dev_en_point = &cpld_info->logic_dev_en_info[i];
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_dev_%d", i);
ret = 0;
ret += of_property_read_string(dev->of_node, buf, (const char **)&name);
if(ret != 0) {
/* Failure to resolve to EN_LOGIC_DEV means no logical device is enabled. No failure is returned */
ret = 0;
break;
}
strncpy(firmware_logic_dev_en_point->dev_name, name, FIRMWARE_DEV_NAME_LEN - 1);
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_addr_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->addr);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_addr_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_mask_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->mask);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_mask_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_en_val_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->en_val);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_en_val_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_dis_val_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->dis_val);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_dis_val_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_width_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->width);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_width_%d ret =%d.\n", i, ret);
break;
}
cpld_info->logic_dev_en_num++;
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("type:%s, chain:%u, chip_index:%u, gpio_en_info_num:%u logic_dev_en_num:%u\n",
cpld_info->type, cpld_info->chain, cpld_info->chip_index, cpld_info->gpio_en_info_num, cpld_info->logic_dev_en_num);
FIRMWARE_DRIVER_DEBUG_VERBOSE("tdi:%u, tck:%u, tms:%u, tdo:%u tck_delay:%u.\n",
cpld_info->tdi, cpld_info->tck, cpld_info->tms, cpld_info->tdo, cpld_info->tck_delay);
return 0;
}
static int firmware_upgrade_config_init(struct device *dev, firmware_cpld_t *cpld_info)
{
int i;
firmware_logic_dev_en_t *firmware_logic_dev_en_point;
firmware_upgrade_device_t *firmware_upgrade_device;
firmware_jtag_device_t jtag_upg_device;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_upgrade_config_init\r\n");
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
if (dev->platform_data == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("platform data config error.\n");
return -1;
}
firmware_upgrade_device = dev->platform_data;
jtag_upg_device = firmware_upgrade_device->upg_type.jtag;
mem_clear(cpld_info, sizeof(firmware_cpld_t));
strncpy(cpld_info->type, firmware_upgrade_device->type, sizeof(cpld_info->type) - 1);
cpld_info->tdi = jtag_upg_device.tdi;
cpld_info->tck = jtag_upg_device.tck;
cpld_info->tms = jtag_upg_device.tms;
cpld_info->tdo = jtag_upg_device.tdo;
cpld_info->chain = firmware_upgrade_device->chain;
cpld_info->chip_index = firmware_upgrade_device->chip_index;
if (jtag_upg_device.tck_delay == 0) {
cpld_info->tck_delay = 60;
FIRMWARE_DRIVER_DEBUG_VERBOSE("no config tck_delay, use default value:%u\n", cpld_info->tck_delay);
} else {
cpld_info->tck_delay = jtag_upg_device.tck_delay;
}
if (firmware_upgrade_device->en_gpio_num > FIRMWARE_EN_INFO_MAX) {
FIRMWARE_DRIVER_DEBUG_ERROR("The number of en_gpio_num:%u configurations exceeds the maximum limit:%u.\n",
firmware_upgrade_device->en_gpio_num, FIRMWARE_EN_INFO_MAX);
return -ENXIO;
}
cpld_info->gpio_en_info_num = firmware_upgrade_device->en_gpio_num;
/* Enable through GPIO */
for (i = 0; i < cpld_info->gpio_en_info_num; i++) {
cpld_info->gpio_en_info[i].en_gpio = firmware_upgrade_device->en_gpio[i];
cpld_info->gpio_en_info[i].en_level = firmware_upgrade_device->en_level[i];
}
if (firmware_upgrade_device->en_logic_num > FIRMWARE_EN_INFO_MAX) {
FIRMWARE_DRIVER_DEBUG_ERROR("The number of en_logic_num:%u configurations exceeds the maximum limit:%u.\n",
firmware_upgrade_device->en_logic_num, FIRMWARE_EN_INFO_MAX);
return -ENXIO;
}
cpld_info->logic_dev_en_num = firmware_upgrade_device->en_logic_num;
/* Enable through register */
for (i = 0; i < cpld_info->logic_dev_en_num; i++) {
firmware_logic_dev_en_point = &cpld_info->logic_dev_en_info[i];
strncpy(firmware_logic_dev_en_point->dev_name, firmware_upgrade_device->en_logic_dev[i],
FIRMWARE_DEV_NAME_LEN - 1);
firmware_logic_dev_en_point->addr = firmware_upgrade_device->en_logic_addr[i];
firmware_logic_dev_en_point->mask = firmware_upgrade_device->en_logic_mask[i];
firmware_logic_dev_en_point->en_val = firmware_upgrade_device->en_logic_en_val[i];
firmware_logic_dev_en_point->dis_val = firmware_upgrade_device->en_logic_dis_val[i];
firmware_logic_dev_en_point->width = firmware_upgrade_device->en_logic_width[i];
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("type:%s, chain:%u, chip_index:%u, gpio_en_info_num:%u logic_dev_en_num:%u\n",
cpld_info->type, cpld_info->chain, cpld_info->chip_index, cpld_info->gpio_en_info_num, cpld_info->logic_dev_en_num);
FIRMWARE_DRIVER_DEBUG_VERBOSE("tdi:%u, tck:%u, tms:%u, tdo:%u tck_delay:%u.\n",
cpld_info->tdi, cpld_info->tck, cpld_info->tms, cpld_info->tdo, cpld_info->tck_delay);
return 0;
}
static int firmware_cpld_probe(struct platform_device *pdev)
{
int ret;
firmware_cpld_t *cpld_info;
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_cpld_probe\r\n");
/* Gets the information in the device tree */
cpld_info = devm_kzalloc(&pdev->dev, sizeof(firmware_cpld_t), GFP_KERNEL);
if (cpld_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc cpld device tree.\n");
return -EPERM;
}
if (pdev->dev.of_node) {
ret = of_firmware_upgrade_config_init(&pdev->dev, cpld_info);
} else {
ret = firmware_upgrade_config_init(&pdev->dev, cpld_info);
}
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("get config init from dts error.\n");
return -EPERM;
}
frm_dev = devm_kzalloc(&pdev->dev, sizeof(firmware_device_t), GFP_KERNEL);
if (frm_dev == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc firmware device.\n");
return -EPERM;
}
/* Based on the link number, determine the name of the device file */
frm_dev->chain = cpld_info->chain;
snprintf(frm_dev->name, FIRMWARE_NAME_LEN - 1, "firmware_cpld_ispvme%d", frm_dev->chain);
strncpy(cpld_info->devname, frm_dev->name, strlen(frm_dev->name) + 1);
INIT_LIST_HEAD(&frm_dev->list);
frm_dev->dev.minor = MISC_DYNAMIC_MINOR;
frm_dev->dev.name = frm_dev->name;
frm_dev->dev.fops = &cpld_dev_fops;
frm_dev->priv = cpld_info;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Register cpld firmware chain:%d, name:%s.\n", frm_dev->chain, frm_dev->name);
ret = firmware_device_register(frm_dev);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to register firmware device.\n");
return -EPERM;
}
platform_set_drvdata(pdev, frm_dev);
return 0;
}
static int __exit firmware_cpld_remove(struct platform_device *pdev)
{
firmware_device_t *frm_dev;
frm_dev = (firmware_device_t *)platform_get_drvdata(pdev);
firmware_device_unregister(frm_dev);
platform_set_drvdata(pdev, NULL);
return 0;
}
static struct of_device_id cpld_match[] = {
{
.compatible = "firmware_cpld_ispvme",
},
{},
};
static struct platform_driver cpld_driver = {
.driver = {
.name = "firmware_cpld_ispvme",
.owner = THIS_MODULE,
.of_match_table = cpld_match,
},
.probe = firmware_cpld_probe,
.remove = firmware_cpld_remove,
};
static firmware_driver_t fmw_drv_cpld = {
.name = "firmware_cpld_ispvme",
.drv = &cpld_driver,
};
int firmware_cpld_init(void)
{
int ret;
INIT_LIST_HEAD(&fmw_drv_cpld.list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("ispvme upgrade driver register \n");
ret = firmware_driver_register(&fmw_drv_cpld);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("ispvme upgrade driver register failed\n");
return ret;
}
return 0;
}
void firmware_cpld_exit(void)
{
firmware_driver_unregister(&fmw_drv_cpld);
INIT_LIST_HEAD(&fmw_drv_cpld.list);
}

View File

@ -0,0 +1,691 @@
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <firmware_ispvme.h>
#include <firmware_cpld_ispvme.h>
#include <firmware_upgrade.h>
/* TCK clock MAX 16MHz */
#define TCK_DELAY (current_fmw_cpld->tck_delay)
#if 0
static firmware_cpld_t default_fmw_cpld;
#endif
static firmware_cpld_t *current_fmw_cpld;
static int TDI_PULL_UP(void);
static int TDI_PULL_DOWN(void);
static int TMS_PULL_UP(void);
static int TMS_PULL_DOWN(void);
static int TCK_PULL_UP(void);
static int TCK_PULL_DOWN(void);
/*
* set_currrent_cpld_info
* function: Save the current device information
* @info: param[in] Information about the device to be updated
*/
static void set_currrent_cpld_info(firmware_cpld_t *info)
{
current_fmw_cpld = info;
}
static int firmware_file_read(const char *path, uint32_t addr, uint8_t *val, size_t size)
{
int ret;
struct file *filp;
loff_t pos;
filp = filp_open(path, O_RDONLY, 0);
if (IS_ERR(filp)) {
FIRMWARE_DRIVER_DEBUG_ERROR("read open failed errno = %ld\r\n", -PTR_ERR(filp));
filp = NULL;
goto exit;
}
pos = (loff_t)addr;
ret = kernel_read(filp, val, size, &pos);
if (ret != size) {
FIRMWARE_DRIVER_DEBUG_ERROR("read kernel_read failed, path=%s, addr=%d, size=%ld, ret=%d\r\n", path, addr, size, ret);
goto exit;
}
filp_close(filp, NULL);
return ret;
exit:
if (filp != NULL) {
filp_close(filp, NULL);
}
return -1;
}
static int firmware_file_write(const char *path, uint32_t addr, uint8_t *val, size_t size)
{
int ret;
struct file *filp;
loff_t pos;
filp = filp_open(path, O_RDWR, 777);
if (IS_ERR(filp)) {
FIRMWARE_DRIVER_DEBUG_ERROR("write open failed errno = %ld\r\n", -PTR_ERR(filp));
filp = NULL;
goto exit;
}
pos = (loff_t)addr;
ret = kernel_write(filp, (void*)val, size, &pos);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("write kernel_write failed, path=%s, addr=%d, size=%ld, ret=%d\r\n", path, addr, size, ret);
goto exit;
}
vfs_fsync(filp, 1);
filp_close(filp, NULL);
return ret;
exit:
if (filp != NULL) {
filp_close(filp, NULL);
}
return -1;
}
/*
* firmware_file_do_work
* function: Sets logical register values
* @path:param[in] Logic device descriptor
* @addr:param[in] Logic device address
* @value:param[in] the register value needs to be set
* @mask:param[in] register mask
* @width:param[in] register bit width
* return: 0:success, <0:failed
*/
static int firmware_file_do_work(char *path, uint32_t addr, uint32_t value, uint32_t mask,
int32_t width)
{
int ret;
uint8_t read_value[4], write_value[4];
uint8_t tmp_read8, tmp_write8, tmp_mask8;
uint32_t tmp_read32, tmp_write32;
FIRMWARE_DRIVER_DEBUG_VERBOSE("path=%s, addr=0x%x, value=0x%x mask=0x%x\r\n", path, addr, value, mask);
if ((width > 4) || (width < 0)) {
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
}
ret = 0;
mem_clear(read_value, sizeof(read_value));
mem_clear(write_value, sizeof(write_value));
ret = firmware_file_read(path, addr, read_value, width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware sysfs read.\r\n");
return -1;
}
switch (width) {
case 1:
tmp_read8 = read_value[0];
tmp_mask8 = (uint8_t)(mask) & 0xFF;
tmp_write8 = (uint8_t)value & 0xFF;
write_value[0] = (tmp_read8 & tmp_mask8) | tmp_write8;
FIRMWARE_DRIVER_DEBUG_VERBOSE("1 byte write val[0]:0x%x", write_value[0]);
break;
case 2:
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
case 4:
memcpy((uint8_t *)&tmp_read32, read_value, 4);
tmp_write32 = (tmp_read32 & mask) | value;
memcpy(write_value, (uint8_t *)&tmp_write32, 4);
FIRMWARE_DRIVER_DEBUG_VERBOSE("4 byte write val[0]:0x%x, val[1]:0x%x, val[2]:0x%x, val[3]:0x%x",
write_value[0], write_value[1], write_value[2], write_value[3]);
break;
default:
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("write logic dev[%s] addr[0x%x].\r\n", path, addr);
ret = firmware_file_write(path, addr, write_value, width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware_file_write %s addr 0x%x failed, ret=%d.\r\n", path, addr, ret);
return -1;
}
return 0;
}
/*
* firmware_upgrade_en
* function: Upgrade access enabling switch
* @flag: !0:enable 0:disable
*/
static int firmware_upgrade_en(int flag)
{
int i;
firmware_logic_dev_en_t *firmware_logic_dev_en_info;
int ret, rv;
char *dev_name;
ret = 0;
FIRMWARE_DRIVER_DEBUG_VERBOSE("%s en switch: gpio en num %d, logic reg en num %d.\n",
flag ? "Open" : "Close", current_fmw_cpld->gpio_en_info_num, current_fmw_cpld->logic_dev_en_num);
for (i = 0; i < current_fmw_cpld->gpio_en_info_num; i++) {
if (flag) {
ret = gpio_request(current_fmw_cpld->gpio_en_info[i].en_gpio, "cpld_ispvme_upgrade");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade EN[%d] GPIO[%d] failed!\n",
i, current_fmw_cpld->gpio_en_info[i].en_gpio);
goto free_gpio;
}
gpio_direction_output(current_fmw_cpld->gpio_en_info[i].en_gpio, current_fmw_cpld->gpio_en_info[i].en_level);
current_fmw_cpld->gpio_en_info[i].flag = 1;
} else {
gpio_set_value(current_fmw_cpld->gpio_en_info[i].en_gpio, !current_fmw_cpld->gpio_en_info[i].en_level);
gpio_free(current_fmw_cpld->gpio_en_info[i].en_gpio);
current_fmw_cpld->gpio_en_info[i].flag = 0;
}
}
for (i = 0; i < current_fmw_cpld->logic_dev_en_num; i++) {
firmware_logic_dev_en_info = &current_fmw_cpld->logic_dev_en_info[i];
dev_name = firmware_logic_dev_en_info->dev_name;
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware sysfs [%d] dev_name[%s] addr[0x%x] mask[0x%x]"
" en_val[0x%x] dis_val[0x%x] width[%d]\n",
i , firmware_logic_dev_en_info->dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->mask, firmware_logic_dev_en_info->en_val,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->width);
if (flag) {
ret = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->en_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Open logic register [%d] EN failed, ret %d.\n", i, ret);
goto free_logic_dev;
} else {
firmware_logic_dev_en_info->flag = 1;
}
} else {
rv = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (rv < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Close logic register [%d] EN failed, ret %d.\n", i, rv);
ret = -1;
}
firmware_logic_dev_en_info->flag = 0;
}
}
return ret;
free_logic_dev:
for (i = 0; i < current_fmw_cpld->logic_dev_en_num; i++) {
firmware_logic_dev_en_info = &current_fmw_cpld->logic_dev_en_info[i];
dev_name = firmware_logic_dev_en_info->dev_name;
if (firmware_logic_dev_en_info->flag == 1) {
ret = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Close logic register [%d] EN failed, ret %d.\n", i, ret);
}
firmware_logic_dev_en_info->flag = 0;
} else {
break;
}
}
free_gpio:
for (i = 0; i < current_fmw_cpld->gpio_en_info_num; i++) {
if (current_fmw_cpld->gpio_en_info[i].flag == 1) {
gpio_set_value(current_fmw_cpld->gpio_en_info[i].en_gpio, !current_fmw_cpld->gpio_en_info[i].en_level);
gpio_free(current_fmw_cpld->gpio_en_info[i].en_gpio);
current_fmw_cpld->gpio_en_info[i].flag = 0;
} else {
break;
}
}
return -1;
}
/*
* init_cpld
* function:Initialize CPLD
* return value: 0 success ; -1 fail
*/
static int init_cpld(void)
{
int ret;
if (current_fmw_cpld == NULL) {
return -1;
}
mdelay(10);
ret = 0;
ret = gpio_request(current_fmw_cpld->tdi, "cpld_ispvme_upgrade");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade TDI GPIO failed!\n");
return ret;
}
ret = gpio_request(current_fmw_cpld->tck, "cpld_ispvme_upgrade");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade TCK GPIO failed!\n");
goto free_tdi;
}
ret = gpio_request(current_fmw_cpld->tms, "cpld_ispvme_upgrade");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade TMS GPIO failed!\n");
goto free_tck;
}
ret = gpio_request(current_fmw_cpld->tdo, "cpld_ispvme_upgrade");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade TDO GPIO failed!\n");
goto free_tms;
}
gpio_direction_output(current_fmw_cpld->tdi, 1);
gpio_direction_output(current_fmw_cpld->tck, 1);
gpio_direction_output(current_fmw_cpld->tms, 1);
gpio_direction_input(current_fmw_cpld->tdo);
ret = firmware_upgrade_en(1);
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: open firmware upgrade en failed, ret %d.\n", ret);
goto free_tdo;
}
#if 0
/* test GPIO */
if (TDI_PULL_UP() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TDI_PULL_UP failed.\n");
goto free_tdo;
}
if (TDI_PULL_DOWN() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TDI_PULL_DOWN failed.\n");
goto free_tdo;
}
if (TMS_PULL_UP() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TMS_PULL_UP failed.\n");
goto free_tdo;
}
if (TMS_PULL_DOWN() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TMS_PULL_DOWN failed.\n");
goto free_tdo;
}
if (TCK_PULL_UP() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TCK_PULL_UP failed.\n");
goto free_tdo;
}
if (TCK_PULL_DOWN() < 0 ) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: TCK_PULL_DOWN failed.\n");
goto free_tdo;
}
#endif
mdelay(10);
return 0;
free_tdo:
gpio_free(current_fmw_cpld->tdo);
free_tms:
gpio_free(current_fmw_cpld->tms);
free_tck:
gpio_free(current_fmw_cpld->tck);
free_tdi:
gpio_free(current_fmw_cpld->tdi);
return ret;
}
/*
* finish_cpld
* function: finish CPLD upgrade operation
* return value: 0 success ; -1 fail
*/
static int finish_cpld(void)
{
int ret;
if (current_fmw_cpld == NULL) {
return -1;
}
mdelay(10);
ret = firmware_upgrade_en(0);
if (ret < 0){
FIRMWARE_DRIVER_DEBUG_ERROR("Error: close firmware upgrade en failed, ret %d.\r\n", ret);
}
gpio_free(current_fmw_cpld->tdi);
gpio_free(current_fmw_cpld->tck);
gpio_free(current_fmw_cpld->tms);
gpio_free(current_fmw_cpld->tdo);
mdelay(10);
return 0;
}
/* Loop waiting for */
static int pull_wait(int gpio, int value) {
int i, j;
/* Timeout time is two seconds */
for (i = 0; i < 20; i++) {
for (j = 0; j < 100; j++) {
if (!!gpio_get_value(gpio) == !!value ) {
return 0;
}
/* The first loop does not delay, normally the first loop can immediately return the result */
if (i) {
mdelay(1);
}
}
/* The CPU is released every 100ms */
schedule();
}
/* timeout */
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Wait gpio %d pull to %d failed.\n", gpio, value);
return -1;
}
/* TDI pull-up */
static int pull_tdi_up(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tdi, 1);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tdi, 1);
}
/* TDI pull-down */
static int pull_tdi_down(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tdi, 0);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tdi, 0);
}
/* TCK pull-up */
static int pull_tck_up(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tck, 1);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tck, 1);
}
/* TCK pull-down */
static int pull_tck_down(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tck, 0);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tck, 0);
}
/* TMS pull-up */
static int pull_tms_up(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tms, 1);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tms, 1);
}
/* TMS pull-down */
static int pull_tms_down(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
gpio_set_value(current_fmw_cpld->tms, 0);
/* Wait for the GPIO value to be set successfully */
return pull_wait(current_fmw_cpld->tms, 0);
}
/* Read TDO */
static int read_tdo(void)
{
if (current_fmw_cpld == NULL) {
return -1;
}
return gpio_get_value(current_fmw_cpld->tdo);
}
static firmware_cpld_function_t function_fmw_cpld = {
.pull_tdi_up = pull_tdi_up,
.pull_tdi_down = pull_tdi_down,
.pull_tck_up = pull_tck_up,
.pull_tck_down = pull_tck_down,
.pull_tms_up = pull_tms_up,
.pull_tms_down = pull_tms_down,
.read_tdo = read_tdo,
.init_cpld = init_cpld,
.finish_cpld = finish_cpld,
};
/*
* TDI_PULL_DOWN
* function: Lower TDI
*/
static int TDI_PULL_DOWN(void)
{
if ( function_fmw_cpld.pull_tdi_down != NULL) {
return function_fmw_cpld.pull_tdi_down();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TDI_PULL_DOWN.\n");
return -1;
}
}
/*
* TDI_PULL_UP
* function: High TDI
*/
static int TDI_PULL_UP(void)
{
if (function_fmw_cpld.pull_tdi_up != NULL) {
return function_fmw_cpld.pull_tdi_up();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TDI_PULL_UP.\n");
return -1;
}
}
/*
* TCK_PULL_DOWN
* function: Lower TCK
*/
static int TCK_PULL_DOWN(void)
{
if (function_fmw_cpld.pull_tck_down != NULL) {
return function_fmw_cpld.pull_tck_down();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TCK_PULL_DOWN.\n");
return -1;
}
}
/*
* TCK_PULL_UP
* function: High TCK
*/
static int TCK_PULL_UP(void)
{
if (function_fmw_cpld.pull_tck_up != NULL) {
return function_fmw_cpld.pull_tck_up();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TCK_PULL_UP.\n");
return -1;
}
}
/*
* TMS_PULL_DOWN
* function: Lower TMS
*/
static int TMS_PULL_DOWN(void)
{
if (function_fmw_cpld.pull_tms_down != NULL) {
return function_fmw_cpld.pull_tms_down();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TMS_PULL_DOWN.\n");
return -1;
}
}
/*
* TMS_PULL_UP
* function: High TMS
*/
static int TMS_PULL_UP(void)
{
if (function_fmw_cpld.pull_tms_up != NULL) {
return function_fmw_cpld.pull_tms_up();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TMS_PULL_UP.\n");
return -1;
}
}
/*
* TDO_READ
* function:Read the TDO level
*/
static int TDO_READ(void)
{
if (function_fmw_cpld.read_tdo != NULL) {
return function_fmw_cpld.read_tdo();
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("NO support TDO_READ.\n");
return -1;
}
}
/*
* cpld_upgrade_init
* function:Initialize GPIO and CPLD
* return value: success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int cpld_upgrade_init(void)
{
int ret;
if (function_fmw_cpld.init_cpld != NULL) {
ret = function_fmw_cpld.init_cpld();
if (ret != FIRMWARE_SUCCESS) {
return ret;
}
}
return FIRMWARE_SUCCESS;
}
/*
* cpld_upgrade_finish
* function:Release GPIO and CPLD
* return value: success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int cpld_upgrade_finish(void)
{
int ret;
if (function_fmw_cpld.finish_cpld != NULL) {
ret = function_fmw_cpld.finish_cpld();
if (ret != FIRMWARE_SUCCESS) {
return ret;
}
}
return FIRMWARE_SUCCESS;
}
/**
* firmware_init_vme
* function: Initialize GPIO,
* @cpld_info: param[in] Information about the device to be written to
*/
int firmware_init_vme(firmware_cpld_t *cpld_info){
int ret;
set_currrent_cpld_info(cpld_info);
/* Initialize GPIO and CPLD */
ret = cpld_upgrade_init();
return ret;
}
/**
* firmware_finish_vme
* function: Release GPIO
* @cpld_info: param[in] Information about the device to be written to
*/
int firmware_finish_vme(firmware_cpld_t *cpld_info){
int ret;
set_currrent_cpld_info(cpld_info);
ret = cpld_upgrade_finish();
return ret;
}
/**
* fwm_cpld_tdi_op
* function: Operate TDI
* @value: param[in] TDI level */
int fwm_cpld_tdi_op(int value)
{
if (value) {
return TDI_PULL_UP();
} else {
return TDI_PULL_DOWN();
}
}
/**
* fwm_cpld_tck_op
* function: Operate TCK
* @value: param[in] TCK level */
int fwm_cpld_tck_op(int value)
{
if (value) {
return TCK_PULL_UP();
} else {
return TCK_PULL_DOWN();
}
}
/**
* fwm_cpld_tms_op
* function: Operate TMS
* value: param[in] TMS level */
int fwm_cpld_tms_op(int value)
{
if (value) {
return TMS_PULL_UP();
} else {
return TMS_PULL_DOWN();
}
}
/**
* fwm_cpld_tdo_op
* function: Read TDO
*/
int fwm_cpld_tdo_op()
{
return TDO_READ();
}

View File

@ -0,0 +1,140 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <firmware_ispvme.h>
int g_firmware_driver_debug = 0;
module_param(g_firmware_driver_debug, int, S_IRUGO | S_IWUSR);
static LIST_HEAD(drv_list);
static LIST_HEAD(dev_list);
/**
* firmware_driver_register
* function:Registered Device Driver
* @fw_drv:param[in] Driver information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_driver_register(firmware_driver_t *fw_drv)
{
int ret;
if (fw_drv == NULL) {
return FIRMWARE_FAILED;
}
ret = platform_driver_register(fw_drv->drv);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: failed to register firmware upgrade driver \n");
return FIRMWARE_FAILED;
}
/* Adds driver information to the driver list */
list_add(&fw_drv->list, &drv_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware upgrade driver register sucess \n");
return FIRMWARE_SUCCESS;
}
/**
* firmware_driver_unregister
* function:unregister Device Driver
* @fw_drv:param[in] Driver information
*/
void firmware_driver_unregister(firmware_driver_t *fw_drv)
{
list_del_init(&fw_drv->list);
platform_driver_unregister(fw_drv->drv);
}
/*
* firmware_get_device_by_minor
* function: Get device information based on minor
*/
firmware_device_t *firmware_get_device_by_minor(int minor)
{
firmware_device_t *tmp;
list_for_each_entry(tmp, &dev_list, list) {
if (tmp->dev.minor == minor) {
return tmp;
}
}
return NULL;
}
/**
* firmware_device_register
* function:Registered Driver Device
* @fw_dev: param[in] Driver information
* return value:success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_device_register(firmware_device_t *fw_dev)
{
int ret;
firmware_device_t *tmp;
if (fw_dev == NULL) {
return FIRMWARE_FAILED;
}
/* Check whether the device file name already exists in the device linked list */
list_for_each_entry(tmp, &dev_list, list) {
if (strcmp(tmp->name, fw_dev->name) == 0) {
return FIRMWARE_FAILED;
}
}
/* Registere device */
ret = misc_register(&fw_dev->dev);
if (ret < 0) {
return FIRMWARE_FAILED;
}
/* Adds a device to the device list */
list_add(&fw_dev->list, &dev_list);
return FIRMWARE_SUCCESS;
}
/**
* firmware_device_unregister
* function: unregister Driver Device
*/
void firmware_device_unregister(firmware_device_t *fw_dev)
{
list_del(&fw_dev->list);
misc_deregister(&fw_dev->dev);
}
static int __init firmware_driver_init(void)
{
int ret;
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver ispvme init.\n");
ret = firmware_cpld_init();
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware driver ispvme init failed.\n");
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}
static void __exit firmware_driver_exit(void)
{
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver ispvme exit.\n");
firmware_cpld_exit();
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
return;
}
module_init(firmware_driver_init);
module_exit(firmware_driver_exit);
MODULE_AUTHOR("support");
MODULE_DESCRIPTION("Firmware upgrade ispvme driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");

View File

@ -0,0 +1,70 @@
#ifndef __FIRMWARE_CPLD_H__
#define __FIRMWARE_CPLD_H__
#define FIRMWARE_DEV_NAME_LEN 32
#define FIRMWARE_MAX_CPLD_NUM 16
#define FIRMWARE_TYPE_LEN 10
#define FIRMWARE_EN_INFO_MAX 16
#define FIRMWARE_EN_INFO_BUF 128
typedef struct firmware_gpio_jtag_en_s {
uint32_t en_gpio; /* GPIO enable pin */
uint32_t en_level; /* GPIO enable level */
int flag; /* init flag; 1-init 0-not init */
} firmware_gpio_jtag_en_t;
typedef struct firmware_logic_dev_en_s {
char dev_name[FIRMWARE_DEV_NAME_LEN]; /* Logical device name */
uint32_t addr; /* Enable register address */
uint32_t mask; /* mask */
uint32_t en_val; /* Enable value */
uint32_t dis_val; /* Disable value*/
uint32_t width; /* width */
int flag; /* init flag; 1-init 0-not init */
} firmware_logic_dev_en_t;
typedef struct firmware_cpld_s {
char devname[FIRMWARE_DEV_NAME_LEN]; /* Device name */
char type[FIRMWARE_TYPE_LEN]; /* interface type */
uint32_t tdi; /* TDI signal corresponding to GPIO pin information */
uint32_t tck; /* TCK signal corresponding to GPIO pin information */
uint32_t tms; /* TMS signal corresponding to GPIO pin information */
uint32_t tdo; /* TDO signal corresponding to GPIO pin information */
uint32_t chain; /* chain num */
uint32_t chip_index; /* chip index */
uint32_t tck_delay; /* Delay time */
uint32_t gpio_en_info_num; /* GPIO Enable Number */
firmware_gpio_jtag_en_t gpio_en_info[FIRMWARE_EN_INFO_MAX]; /* GPIO Enable Information */
uint32_t logic_dev_en_num; /* Register Enable Number */
firmware_logic_dev_en_t logic_dev_en_info[FIRMWARE_EN_INFO_MAX]; /* Register Enable Information */
} firmware_cpld_t;
typedef struct firmware_cpld_function_s{
int (*pull_tdi_up)(void); /* TDI pull-up */
int (*pull_tdi_down)(void); /* TDI pull-down */
int (*pull_tck_up)(void); /* TCK pull-up */
int (*pull_tck_down)(void); /* TCK pull-down */
int (*pull_tms_up)(void); /* TMS pull-up */
int (*pull_tms_down)(void); /* TCK pull-down */
int (*read_tdo)(void); /* Read TDO */
int (*init_cpld)(void); /* CPLD upgrade initializes the operation */
int (*init_chip)(int chain); /* chip initializes the operation */
int (*finish_chip)(int chain); /* chip completes the operation*/
int (*finish_cpld)(void); /* CPLD upgrade completes the operation */
int (*get_version)(int chain, char *ver, int len); /* get version */
}firmware_cpld_function_t;
/* operate TDI */
extern int fwm_cpld_tdi_op(int value);
/* operate TCK */
extern int fwm_cpld_tck_op(int value);
/* operate TMS */
extern int fwm_cpld_tms_op(int value);
/* operate TDO */
extern int fwm_cpld_tdo_op(void);
/* VME upgrade mode completes the operation*/
extern int firmware_finish_vme(firmware_cpld_t *cpld_info);
/* VME upgrade mode initializes the operation*/
extern int firmware_init_vme(firmware_cpld_t *cpld_info);
#endif /* __FIRMWARE_CPLD_H__ */

View File

@ -0,0 +1,86 @@
#ifndef __FIRMWARE_H__
#define __FIRMWARE_H__
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <asm/ioctl.h>
/* Debug switch level */
typedef enum {
FIRWMARE_VERBOSE,
FIRWMARE_WARN,
FIRWMARE_ERROR,
FIRWMARE_END,
} firmware_debug_level_t;
#define FIRMWARE_DRIVER_DEBUG_VERBOSE(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_VERBOSE)) { \
printk(KERN_INFO "[FIRMWARW_DRIVER_ISPVME][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_DRIVER_DEBUG_ERROR(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_ERROR)) { \
printk(KERN_ERR "[FIRMWARW_DRIVER_ISPVME][ERR][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_NAME_LEN 48
#define FIRMWARE_FAILED (-1)
#define FIRMWARE_SUCCESS 0
/* ioctl publi command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_COMMON_TYPE 'C'
#define FIRMWARE_GET_CHIPNAME _IOR(FIRMWARE_COMMON_TYPE, 0, char) /* get the chip name */
#define FIRMWARE_GET_VERSION _IOR(FIRMWARE_COMMON_TYPE, 2, int) /* get version */
/* firmware cpld ispvme driver ioctl command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_VME_TYPE 'V'
#define FIRMWARE_JTAG_TDI _IOR(FIRMWARE_VME_TYPE, 0, char)
#define FIRMWARE_JTAG_TDO _IOR(FIRMWARE_VME_TYPE, 1, char)
#define FIRMWARE_JTAG_TCK _IOR(FIRMWARE_VME_TYPE, 2, char)
#define FIRMWARE_JTAG_TMS _IOR(FIRMWARE_VME_TYPE, 3, char)
#define FIRMWARE_JTAG_EN _IOR(FIRMWARE_VME_TYPE, 4, char)
#define FIRMWARE_JTAG_INIT _IOR(FIRMWARE_VME_TYPE, 7, char) /* enable upgrade access */
#define FIRMWARE_JTAG_FINISH _IOR(FIRMWARE_VME_TYPE, 8, char) /* disable upgrade access */
typedef struct cmd_info_s {
uint32_t size;
void __user *data;
} cmd_info_t;
typedef struct firmware_device_s {
struct list_head list; /* device list */
uint32_t chain; /* chain number */
char name[FIRMWARE_NAME_LEN]; /* name */
struct miscdevice dev; /* device */
void *priv; /* private data */
} firmware_device_t;
typedef struct firmware_driver_s {
struct list_head list; /* list */
char name[FIRMWARE_NAME_LEN]; /* name */
struct platform_driver *drv; /* driver */
void *priv; /* private data */
} firmware_driver_t;
extern int g_firmware_driver_debug;
/* Get device information based on minor */
extern firmware_device_t *firmware_get_device_by_minor(int minor);
/* Registere device */
extern int firmware_device_register(firmware_device_t *fw_dev);
/* Unregister device */
extern void firmware_device_unregister(firmware_device_t *fw_dev);
/* Registere driver */
extern int firmware_driver_register(firmware_driver_t *fw_drv);
/* Unregister driver */
extern void firmware_driver_unregister(firmware_driver_t *fw_drv);
/* CPLD upgrade initialized */
extern int firmware_cpld_init(void);
/* CPLD unload function */
extern void firmware_cpld_exit(void);
#endif /* end of __FIRMWARE_H__ */

View File

@ -0,0 +1,22 @@
#include $(top_srcdir)/debian/rules
#KERNELDIR := ${KBUILD_OUTPUT}
PWD = $(shell pwd)
EXTRA_CFLAGS:= -I$(M)/include
MAKEFILE_FILE_PATH = $(abspath $(lastword $(MAKEFILE_LIST)))
FIRMWARE_UPGRADE_PATH = $(abspath $(MAKEFILE_FILE_PATH)/../../include)
EXTRA_CFLAGS+= -I$(FIRMWARE_UPGRADE_PATH)
EXTRA_CFLAGS+= -Wall
firmware_driver_sysfs-objs := firmware.o
firmware_driver_sysfs-objs += firmware_sysfs.o firmware_sysfs_upgrade.o
#ifndef CONFIG_FRM_PRODUCT_FILE
$(warning $(firmware_driver_sysfs-objs))
obj-m := firmware_driver_sysfs.o
all:
$(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules
@if [ ! -d $(common_module_dir) ]; then mkdir -p $(common_module_dir) ;fi
cp -p $(PWD)/*.ko $(common_module_dir)

View File

@ -0,0 +1,143 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <firmware_sysfs.h>
int g_firmware_driver_debug = 0;
module_param(g_firmware_driver_debug, int, S_IRUGO | S_IWUSR);
static LIST_HEAD(drv_list);
static LIST_HEAD(dev_list);
/**
* firmware_driver_register
* function:Registered Device Driver
* @fw_drv:param[in] Driver information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_driver_register(firmware_driver_t *fw_drv)
{
int ret;
if (fw_drv == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Parameter error.\n");
return FIRMWARE_FAILED;
}
ret = platform_driver_register(fw_drv->drv);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: failed to register firmware upgrade driver \n");
return FIRMWARE_FAILED;
}
/* Adds driver information to the driver list */
list_add(&fw_drv->list, &drv_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware upgrade driver register sucess \n");
return FIRMWARE_SUCCESS;
}
/**
* firmware_driver_unregister
* function:unregister Device Driver
* @fw_drv:param[in] Driver information
*/
void firmware_driver_unregister(firmware_driver_t *fw_drv)
{
list_del_init(&fw_drv->list);
platform_driver_unregister(fw_drv->drv);
}
/*
* firmware_get_device_by_minor
* function: Get device information based on minor
*/
firmware_device_t *firmware_get_device_by_minor(int minor)
{
firmware_device_t *tmp;
list_for_each_entry(tmp, &dev_list, list) {
if (tmp->dev.minor == minor) {
return tmp;
}
}
return NULL;
}
/**
* firmware_device_register
* function:Registered Driver Device
* @fw_dev: param[in] Driver information
* return value:success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_device_register(firmware_device_t *fw_dev)
{
int ret;
firmware_device_t *tmp;
if (fw_dev == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Parameter error.\n");
return FIRMWARE_FAILED;
}
/* Check whether the device file name already exists in the device linked list */
list_for_each_entry(tmp, &dev_list, list) {
if (strcmp(tmp->name, fw_dev->name) == 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("devie %s already exists.\n", fw_dev->name);
return FIRMWARE_FAILED;
}
}
ret = misc_register(&fw_dev->dev);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("register misc error, ret=%d.\n", ret);
return FIRMWARE_FAILED;
}
/* Adds driver information to the driver list */
list_add(&fw_dev->list, &dev_list);
return FIRMWARE_SUCCESS;
}
/**
* firmware_device_unregister
* function: unregister Driver Device
*/
void firmware_device_unregister(firmware_device_t *fw_dev)
{
list_del(&fw_dev->list);
misc_deregister(&fw_dev->dev);
}
static int __init firmware_driver_init(void)
{
int ret;
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver sysfs init.\n");
ret = firmware_sysfs_init();
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware driver sysfs init failed.\n");
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}
static void __exit firmware_driver_exit(void)
{
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware driver sysfs exit.\n");
firmware_sysfs_exit();
INIT_LIST_HEAD(&drv_list);
INIT_LIST_HEAD(&dev_list);
return;
}
module_init(firmware_driver_init);
module_exit(firmware_driver_exit);
MODULE_AUTHOR("support");
MODULE_DESCRIPTION("Firmware upgrade driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");

View File

@ -0,0 +1,495 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/of.h>
#include <linux/uaccess.h>
#include <firmware_sysfs.h>
#include <firmware_sysfs_upgrade.h>
#include <firmware_upgrade.h>
static int firmware_sysfs_open(struct inode *inode, struct file *file)
{
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Open device.\n");
frm_dev = firmware_get_device_by_minor(MINOR(inode->i_rdev));
if (frm_dev == NULL) {
return -ENXIO;
}
file->private_data = frm_dev;
return FIRMWARE_SUCCESS;
}
static ssize_t firmware_sysfs_read (struct file *file, char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static ssize_t firmware_sysfs_write (struct file *file, const char __user *buf, size_t count,
loff_t *offset)
{
return 0;
}
static loff_t firmware_sysfs_llseek(struct file *file, loff_t offset, int origin)
{
return 0;
}
/* firmware_sysfs_ioctl
* function:ioctl command parsing function
* @file: param[in] device file name
* @cmd: param[in] command
* @arg: param[in] the parameters in the command
* return value: success-FIRMWARE_SUCCESS; fail:other value
*/
static long firmware_sysfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
void __user *argp;
firmware_device_t *frm_dev;
firmware_sysfs_t *sysfs_info;
int ret;
/* Get device private data */
frm_dev = (firmware_device_t *)file->private_data;
sysfs_info = NULL;
if (frm_dev != NULL) {
if (frm_dev->priv != NULL) {
sysfs_info = (firmware_sysfs_t *)frm_dev->priv;
}
}
if (sysfs_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to frm_dev->priv sysfs info.\n");
return FIRMWARE_FAILED;
}
argp = (void __user *)arg;
switch (cmd) {
case FIRMWARE_SYSFS_INIT:
/* enable upgrade access */
ret = firmware_init_dev_loc(sysfs_info);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to init upgrade.(chain = %d)\n",
frm_dev != NULL ? frm_dev->chain : -1);
return FIRMWARE_FAILED;
}
break;
case FIRMWARE_SYSFS_FINISH:
/* disable upgrade access */
ret = firmware_finish_dev_loc(sysfs_info);
if (ret != FIRMWARE_SUCCESS) {
FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to release upgrade.(chain = %d)\n",
frm_dev != NULL ? frm_dev->chain : -1);
return FIRMWARE_FAILED;
}
break;
case FIRMWARE_SYSFS_SPI_INFO:
/* Get SPI logic device information */
if (copy_to_user(argp, &sysfs_info->info.spi_logic_info, sizeof(firmware_spi_logic_info_t))) {
return -EFAULT;
}
break;
case FIRMWARE_SYSFS_DEV_FILE_INFO:
/*Get logic device information */
if (copy_to_user(argp, &sysfs_info->info.dev_file_info, sizeof(firmware_dev_file_info_t))) {
return -EFAULT;
}
break;
case FIRMWARE_SYSFS_MTD_INFO:
/*Get logic device information */
if (copy_to_user(argp, &sysfs_info->info.mtd_info, sizeof(firmware_mtd_info_t))) {
return -EFAULT;
}
break;
default:
FIRMWARE_DRIVER_DEBUG_ERROR("not find cmd: %d\r\n", cmd);
return -ENOTTY;
} /* End of switch */
return FIRMWARE_SUCCESS;
}
static int firmware_sysfs_release(struct inode *inode, struct file *file)
{
return 0;
}
static const struct file_operations sysfs_dev_fops = {
.owner = THIS_MODULE,
.llseek = firmware_sysfs_llseek,
.read = firmware_sysfs_read,
.write = firmware_sysfs_write,
.unlocked_ioctl = firmware_sysfs_ioctl,
.open = firmware_sysfs_open,
.release = firmware_sysfs_release,
};
/* Gets the information in the device tree */
static int of_firmware_upgrade_config_init(struct device *dev, firmware_sysfs_t *sysfs_info)
{
int ret;
char *name;
int8_t buf[64];
int i;
firmware_logic_dev_en_t *firmware_logic_dev_en_point;
uint32_t test_base, test_size;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_dev_loc_config_init\r\n");
if (sysfs_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
mem_clear(sysfs_info, sizeof(firmware_sysfs_t));
ret = 0;
ret += of_property_read_string(dev->of_node, "type", (const char **)&name);
ret += of_property_read_u32(dev->of_node, "chain", &sysfs_info->chain);
ret += of_property_read_u32(dev->of_node, "chip_index", &sysfs_info->chip_index);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(sysfs_info->type, name, sizeof(sysfs_info->type) - 1);
ret = of_property_read_u32(dev->of_node, "test_base", &test_base);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config test_base, ret:%d.\n", ret);
test_base = 0;
}
ret = of_property_read_u32(dev->of_node, "test_size", &test_size);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config test_size, ret:%d.\n", ret);
test_size = 0;
}
if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_SPI_LOGIC) == 0) {
ret = of_property_read_string(dev->of_node, "dev_name", (const char **)&name);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config dev_name error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(sysfs_info->info.spi_logic_info.dev_name, name, FIRMWARE_DEV_NAME_LEN - 1);
ret = of_property_read_u32(dev->of_node, "flash_base", &sysfs_info->info.spi_logic_info.flash_base);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config flash_base error, ret:%d.\n", ret);
return -ENXIO;
}
ret = of_property_read_u32(dev->of_node, "ctrl_base", &sysfs_info->info.spi_logic_info.ctrl_base);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config ctrl_base error, ret:%d.\n", ret);
return -ENXIO;
}
sysfs_info->info.spi_logic_info.test_base = test_base;
sysfs_info->info.spi_logic_info.test_size = test_size;
} else if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_SYSFS) == 0) {
ret = of_property_read_string(dev->of_node, "sysfs_name", (const char **)&name);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config sysfs_name error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(sysfs_info->info.dev_file_info.sysfs_name, name, FIRMWARE_DEV_NAME_LEN - 1);
ret = of_property_read_u32(dev->of_node, "dev_base", &sysfs_info->info.dev_file_info.dev_base);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_VERBOSE("dts don't config dev_base, dev_base is 0.\n");
sysfs_info->info.dev_file_info.dev_base = 0;
}
ret = of_property_read_u32(dev->of_node, "per_len", &sysfs_info->info.dev_file_info.per_len);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_VERBOSE("dts don't config per_len, per_len is 0.\n");
sysfs_info->info.dev_file_info.per_len = 0;
}
sysfs_info->info.dev_file_info.test_base = test_base;
sysfs_info->info.dev_file_info.test_size = test_size;
} else if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_MTD) == 0) {
ret = of_property_read_string(dev->of_node, "mtd_name", (const char **)&name);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config mtd_name error, ret:%d.\n", ret);
return -ENXIO;
}
strncpy(sysfs_info->info.mtd_info.mtd_name, name, FIRMWARE_DEV_NAME_LEN - 1);
ret = of_property_read_u32(dev->of_node, "flash_base", &sysfs_info->info.mtd_info.flash_base);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config flash_base error, ret:%d.\n", ret);
return -ENXIO;
}
sysfs_info->info.mtd_info.test_base = test_base;
sysfs_info->info.mtd_info.test_size = test_size;
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("dts config sysfs type[%s] is not support, ret:%d.\n", sysfs_info->type, ret);
return -ENXIO;
}
sysfs_info->gpio_en_info_num = 0;
/* Enable through GPIO */
for (i = 0; i < FIRMWARE_EN_INFO_MAX; i++) {
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_gpio_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &sysfs_info->gpio_en_info[i].en_gpio);
if(ret != 0) {
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_level_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &sysfs_info->gpio_en_info[i].en_level);
if(ret != 0) {
break;
}
sysfs_info->gpio_en_info_num++;
}
sysfs_info->logic_dev_en_num = 0;
/* Enable through register */
for (i = 0; i < FIRMWARE_EN_INFO_MAX; i++) {
firmware_logic_dev_en_point = &sysfs_info->logic_dev_en_info[i];
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_dev_%d", i);
ret = 0;
ret += of_property_read_string(dev->of_node, buf, (const char **)&name);
if(ret != 0) {
/* Failure to resolve to EN_LOGIC_DEV means no logical device is enabled. No failure is returned */
ret = 0;
break;
}
strncpy(firmware_logic_dev_en_point->dev_name, name, FIRMWARE_DEV_NAME_LEN - 1);
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_addr_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->addr);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_addr_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_mask_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->mask);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_mask_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_en_val_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->en_val);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_en_val_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_dis_val_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->dis_val);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_dis_val_%d ret =%d.\n", i, ret);
break;
}
mem_clear(buf, sizeof(buf));
snprintf(buf, sizeof(buf) - 1, "en_logic_width_%d", i);
ret = of_property_read_u32(dev->of_node, buf, &firmware_logic_dev_en_point->width);
if (ret != 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to config en en_logic_width_%d ret =%d.\n", i, ret);
break;
}
sysfs_info->logic_dev_en_num++;
}
return ret;
}
static int firmware_upgrade_config_init(struct device *dev, firmware_sysfs_t *sysfs_info)
{
int i;
firmware_logic_dev_en_t *firmware_logic_dev_en_point;
firmware_upgrade_device_t *firmware_upgrade_device;
firmware_sysfs_device_t sysfs_upg_device;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_dev_loc_config_init\r\n");
if (sysfs_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("info is null\r\n");
return -1;
}
if (dev->platform_data == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("platform data config error.\n");
return -1;
}
firmware_upgrade_device = dev->platform_data;
sysfs_upg_device = firmware_upgrade_device->upg_type.sysfs;
mem_clear(sysfs_info, sizeof(firmware_sysfs_t));
strncpy(sysfs_info->type, firmware_upgrade_device->type, sizeof(sysfs_info->type) - 1);
sysfs_info->chain = firmware_upgrade_device->chain;
sysfs_info->chip_index = firmware_upgrade_device->chip_index;
if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_SPI_LOGIC) == 0) {
strncpy(sysfs_info->info.spi_logic_info.dev_name, sysfs_upg_device.dev_name, FIRMWARE_DEV_NAME_LEN - 1);
sysfs_info->info.spi_logic_info.flash_base = sysfs_upg_device.flash_base;
sysfs_info->info.spi_logic_info.ctrl_base = sysfs_upg_device.ctrl_base;
sysfs_info->info.spi_logic_info.test_base = sysfs_upg_device.test_base;
sysfs_info->info.spi_logic_info.test_size = sysfs_upg_device.test_size;
} else if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_SYSFS) == 0) {
strncpy(sysfs_info->info.dev_file_info.sysfs_name, sysfs_upg_device.sysfs_name, FIRMWARE_DEV_NAME_LEN - 1);
sysfs_info->info.dev_file_info.dev_base = sysfs_upg_device.dev_base;
sysfs_info->info.dev_file_info.per_len = sysfs_upg_device.per_len;
sysfs_info->info.dev_file_info.test_base = sysfs_upg_device.test_base;
sysfs_info->info.dev_file_info.test_size = sysfs_upg_device.test_size;
} else if (strcmp(sysfs_info->type, FIRMWARE_SYSFS_TYPE_MTD) == 0) {
strncpy(sysfs_info->info.mtd_info.mtd_name, sysfs_upg_device.mtd_name, FIRMWARE_DEV_NAME_LEN - 1);
sysfs_info->info.mtd_info.flash_base = sysfs_upg_device.flash_base;
sysfs_info->info.mtd_info.test_base = sysfs_upg_device.test_base;
sysfs_info->info.mtd_info.test_size = sysfs_upg_device.test_size;
} else {
FIRMWARE_DRIVER_DEBUG_ERROR("config sysfs type[%s] is not support.\n", sysfs_info->type);
return -ENXIO;
}
if (firmware_upgrade_device->en_gpio_num > FIRMWARE_EN_INFO_MAX) {
FIRMWARE_DRIVER_DEBUG_ERROR("The number of en_gpio_num:%u configurations exceeds the maximum limit:%u.\n",
firmware_upgrade_device->en_gpio_num, FIRMWARE_EN_INFO_MAX);
return -ENXIO;
}
sysfs_info->gpio_en_info_num = firmware_upgrade_device->en_gpio_num;
/* Enable through GPIO */
for (i = 0; i < sysfs_info->gpio_en_info_num; i++) {
sysfs_info->gpio_en_info[i].en_gpio = firmware_upgrade_device->en_gpio[i];
sysfs_info->gpio_en_info[i].en_level = firmware_upgrade_device->en_level[i];
}
if (firmware_upgrade_device->en_logic_num > FIRMWARE_EN_INFO_MAX) {
FIRMWARE_DRIVER_DEBUG_ERROR("The number of en_logic_num:%u configurations exceeds the maximum limit:%u.\n",
firmware_upgrade_device->en_logic_num, FIRMWARE_EN_INFO_MAX);
return -ENXIO;
}
sysfs_info->logic_dev_en_num = firmware_upgrade_device->en_logic_num;
/* Enable through register */
for (i = 0; i < sysfs_info->logic_dev_en_num; i++) {
firmware_logic_dev_en_point = &sysfs_info->logic_dev_en_info[i];
strncpy(firmware_logic_dev_en_point->dev_name, firmware_upgrade_device->en_logic_dev[i], FIRMWARE_DEV_NAME_LEN - 1);
firmware_logic_dev_en_point->addr = firmware_upgrade_device->en_logic_addr[i];
firmware_logic_dev_en_point->mask = firmware_upgrade_device->en_logic_mask[i];
firmware_logic_dev_en_point->en_val = firmware_upgrade_device->en_logic_en_val[i];
firmware_logic_dev_en_point->dis_val = firmware_upgrade_device->en_logic_dis_val[i];
firmware_logic_dev_en_point->width = firmware_upgrade_device->en_logic_width[i];
}
return 0;
}
static int firmware_sysfs_probe(struct platform_device *pdev)
{
int ret;
firmware_sysfs_t *sysfs_info;
firmware_device_t *frm_dev;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Enter firmware_sysfs_probe\r\n");
sysfs_info = devm_kzalloc(&pdev->dev, sizeof(firmware_sysfs_t), GFP_KERNEL);
if (sysfs_info == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc device tree.\n");
return -EPERM;
}
if (pdev->dev.of_node) {
ret = of_firmware_upgrade_config_init(&pdev->dev, sysfs_info);
} else {
ret = firmware_upgrade_config_init(&pdev->dev, sysfs_info);
}
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("get config init from dts error.\n");
return -EPERM;
}
frm_dev = devm_kzalloc(&pdev->dev, sizeof(firmware_device_t), GFP_KERNEL);
if (frm_dev == NULL) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to kzalloc firmware device.\n");
return -EPERM;
}
/* Based on the link number, determine the name of the device file */
frm_dev->chain = sysfs_info->chain;
snprintf(frm_dev->name, FIRMWARE_NAME_LEN - 1, "firmware_sysfs%d", frm_dev->chain);
strncpy(sysfs_info->devname, frm_dev->name, strlen(frm_dev->name) + 1);
INIT_LIST_HEAD(&frm_dev->list);
frm_dev->dev.minor = MISC_DYNAMIC_MINOR;
frm_dev->dev.name = frm_dev->name;
frm_dev->dev.fops = &sysfs_dev_fops;
frm_dev->priv = sysfs_info;
FIRMWARE_DRIVER_DEBUG_VERBOSE("Register sysfs firmware chain:%d, name:%s.\n", frm_dev->chain, frm_dev->name);
ret = firmware_device_register(frm_dev);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Failed to register firmware device.\n");
return -EPERM;
}
platform_set_drvdata(pdev, frm_dev);
return 0;
}
static int __exit firmware_sysfs_remove(struct platform_device *pdev)
{
firmware_device_t *frm_dev;
frm_dev = (firmware_device_t *)platform_get_drvdata(pdev);
firmware_device_unregister(frm_dev);
platform_set_drvdata(pdev, NULL);
return 0;
}
static struct of_device_id sysfs_match[] = {
{
.compatible = "firmware_sysfs",
},
{},
};
static struct platform_driver sysfs_driver = {
.driver = {
.name = "firmware_sysfs",
.owner = THIS_MODULE,
.of_match_table = sysfs_match,
},
.probe = firmware_sysfs_probe,
.remove = firmware_sysfs_remove,
};
static firmware_driver_t fmw_drv_sysfs = {
.name = "firmware_sysfs",
.drv = &sysfs_driver,
};
int firmware_sysfs_init(void)
{
int ret;
INIT_LIST_HEAD(&fmw_drv_sysfs.list);
FIRMWARE_DRIVER_DEBUG_VERBOSE("sysfs upgrade driver register \n");
ret = firmware_driver_register(&fmw_drv_sysfs);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("sysfs upgrade driver register failed\n");
return ret;
}
return 0;
}
void firmware_sysfs_exit(void)
{
firmware_driver_unregister(&fmw_drv_sysfs);
INIT_LIST_HEAD(&fmw_drv_sysfs.list);
}

View File

@ -0,0 +1,258 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <firmware_sysfs.h>
#include <firmware_sysfs_upgrade.h>
#include <firmware_upgrade.h>
static int firmware_file_read(const char *path, uint32_t addr, uint8_t *val, size_t size)
{
int ret;
struct file *filp;
loff_t pos;
filp = filp_open(path, O_RDONLY, 0);
if (IS_ERR(filp)) {
FIRMWARE_DRIVER_DEBUG_ERROR("read open failed errno = %ld\r\n", -PTR_ERR(filp));
filp = NULL;
goto exit;
}
pos = (loff_t)addr;
ret = kernel_read(filp, val, size, &pos);
if (ret != size) {
FIRMWARE_DRIVER_DEBUG_ERROR("read kernel_read failed, path=%s, addr=%d, size=%ld, ret=%d\r\n", path, addr, size, ret);
goto exit;
}
filp_close(filp, NULL);
return ret;
exit:
if (filp != NULL) {
filp_close(filp, NULL);
}
return -1;
}
static int firmware_file_write(const char *path, uint32_t addr, uint8_t *val, size_t size)
{
int ret;
struct file *filp;
loff_t pos;
filp = filp_open(path, O_RDWR, 777);
if (IS_ERR(filp)) {
FIRMWARE_DRIVER_DEBUG_ERROR("write open failed errno = %ld\r\n", -PTR_ERR(filp));
filp = NULL;
goto exit;
}
pos = (loff_t)addr;
ret = kernel_write(filp, (void*)val, size, &pos);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("write kernel_write failed, path=%s, addr=%d, size=%ld, ret=%d\r\n", path, addr, size, ret);
goto exit;
}
vfs_fsync(filp, 1);
filp_close(filp, NULL);
return ret;
exit:
if (filp != NULL) {
filp_close(filp, NULL);
}
return -1;
}
/*
* firmware_file_do_work
* function: Sets logical register values
* @path:param[in] Logic device descriptor
* @addr:param[in] Logic device address
* @value:param[in] the register value needs to be set
* @mask:param[in] register mask
* @width:param[in] register bit width
* return: 0:success, <0:failed
*/
static int firmware_file_do_work(char *path, uint32_t addr, uint32_t value, uint32_t mask,
int32_t width)
{
int ret;
uint8_t read_value[4], write_value[4];
uint8_t tmp_read8, tmp_write8, tmp_mask8;
uint32_t tmp_read32, tmp_write32;
FIRMWARE_DRIVER_DEBUG_VERBOSE("path=%s, addr=0x%x, value=0x%x mask=0x%x\r\n", path, addr, value, mask);
if ((width > 4) || (width < 0)) {
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
}
ret = 0;
mem_clear(read_value, sizeof(read_value));
mem_clear(write_value, sizeof(write_value));
ret = firmware_file_read(path, addr, read_value, width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware sysfs read.\r\n");
return -1;
}
switch (width) {
case 1:
tmp_read8 = read_value[0];
tmp_mask8 = (uint8_t)(mask) & 0xFF;
tmp_write8 = (uint8_t)value & 0xFF;
write_value[0] = (tmp_read8 & tmp_mask8) | tmp_write8;
FIRMWARE_DRIVER_DEBUG_VERBOSE("1 byte write val[0]:0x%x", write_value[0]);
break;
case 2:
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
case 4:
memcpy((uint8_t *)&tmp_read32, read_value, 4);
tmp_write32 = (tmp_read32 & mask) | value;
memcpy(write_value, (uint8_t *)&tmp_write32, 4);
FIRMWARE_DRIVER_DEBUG_VERBOSE("4 byte write val[0]:0x%x, val[1]:0x%x, val[2]:0x%x, val[3]:0x%x",
write_value[0], write_value[1], write_value[2], write_value[3]);
break;
default:
FIRMWARE_DRIVER_DEBUG_ERROR("width %d is not support.\r\n", width);
return -1;
}
FIRMWARE_DRIVER_DEBUG_VERBOSE("write logic dev[%s] addr[0x%x].\r\n", path, addr);
ret = firmware_file_write(path, addr, write_value, width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("firmware_file_write %s addr 0x%x failed, ret=%d.\r\n", path, addr, ret);
return -1;
}
return 0;
}
/*
* firmware_upgrade_en
* function:param[in] Upgrade access enabling switch
* @flag:param[in] !0:enable 0:disable
* return: 0:success, <0:failed
*/
static int firmware_upgrade_en(firmware_sysfs_t *sysfs_info, int flag)
{
int i;
firmware_logic_dev_en_t *firmware_logic_dev_en_info;
int ret, rv;
char *dev_name;
ret = 0;
FIRMWARE_DRIVER_DEBUG_VERBOSE("%s en switch: gpio en num %d, logic reg en num %d.\n",
flag ? "Open" : "Close", sysfs_info->gpio_en_info_num, sysfs_info->logic_dev_en_num);
for (i = 0; i < sysfs_info->gpio_en_info_num; i++) {
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware sysfs [%d] gpio[%d] en_level[%d]\n",
i, sysfs_info->gpio_en_info[i].en_gpio, sysfs_info->gpio_en_info[i].en_level);
if (flag) {
ret = gpio_request(sysfs_info->gpio_en_info[i].en_gpio, "sysfs_upgrade_gpio_en");
if (ret) {
FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_ispvme_upgrade EN[%d] GPIO[%d] failed!\n",
i, sysfs_info->gpio_en_info[i].en_gpio);
goto free_gpio;
}
gpio_direction_output(sysfs_info->gpio_en_info[i].en_gpio, sysfs_info->gpio_en_info[i].en_level);
sysfs_info->gpio_en_info[i].flag = 1;
} else {
gpio_set_value(sysfs_info->gpio_en_info[i].en_gpio, !sysfs_info->gpio_en_info[i].en_level);
gpio_free(sysfs_info->gpio_en_info[i].en_gpio);
sysfs_info->gpio_en_info[i].flag = 0;
}
}
for (i = 0; i < sysfs_info->logic_dev_en_num; i++) {
firmware_logic_dev_en_info = &sysfs_info->logic_dev_en_info[i];
dev_name = firmware_logic_dev_en_info->dev_name;
FIRMWARE_DRIVER_DEBUG_VERBOSE("firmware sysfs [%d] dev_name[%s] addr[0x%x] mask[0x%x]"
" en_val[0x%x] dis_val[0x%x] width[%d]\n",
i , firmware_logic_dev_en_info->dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->mask, firmware_logic_dev_en_info->en_val,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->width);
if (flag) {
ret = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->en_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Open logic register [%d] EN failed, ret %d.\n", i, ret);
goto free_logic_dev;
} else {
firmware_logic_dev_en_info->flag = 1;
}
} else {
rv = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (rv < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Close logic register [%d] EN failed, ret %d.\n", i, rv);
ret = -1;
}
firmware_logic_dev_en_info->flag = 0;
}
}
return ret;
free_logic_dev:
for (i = 0; i < sysfs_info->logic_dev_en_num; i++) {
firmware_logic_dev_en_info = &sysfs_info->logic_dev_en_info[i];
dev_name = firmware_logic_dev_en_info->dev_name;
if (firmware_logic_dev_en_info->flag == 1) {
ret = firmware_file_do_work(dev_name, firmware_logic_dev_en_info->addr,
firmware_logic_dev_en_info->dis_val, firmware_logic_dev_en_info->mask,
firmware_logic_dev_en_info->width);
if (ret < 0) {
FIRMWARE_DRIVER_DEBUG_ERROR("Close logic register [%d] EN failed, ret %d.\n", i, ret);
}
firmware_logic_dev_en_info->flag = 0;
} else {
break;
}
}
free_gpio:
for (i = 0; i < sysfs_info->gpio_en_info_num; i++) {
if (sysfs_info->gpio_en_info[i].flag == 1) {
gpio_set_value(sysfs_info->gpio_en_info[i].en_gpio, !sysfs_info->gpio_en_info[i].en_level);
gpio_free(sysfs_info->gpio_en_info[i].en_gpio);
sysfs_info->gpio_en_info[i].flag = 0;
} else {
break;
}
}
return -1;
}
/*
* firmware_init_dev_loc
* function: init logic device, enable upgrade access
* return: 0:success, <0:failed
*/
int firmware_init_dev_loc(firmware_sysfs_t *sysfs_info)
{
int ret;
ret = firmware_upgrade_en(sysfs_info, 1);
return ret;
}
/*
* firmware_finish_dev_loc
* function: finish logic device, disable upgrade access
* return: 0:success, <0:failed
*/
int firmware_finish_dev_loc(firmware_sysfs_t *sysfs_info){
int ret;
ret = firmware_upgrade_en(sysfs_info, 0);
return ret;
}

View File

@ -0,0 +1,88 @@
#ifndef __FIRMWARE_SYSFS_H__
#define __FIRMWARE_SYSFS_H__
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <asm/ioctl.h>
/* Debug switch level */
typedef enum {
FIRWMARE_VERBOSE,
FIRWMARE_WARN,
FIRWMARE_ERROR,
FIRWMARE_END,
} firmware_debug_level_t;
#define FIRMWARE_DRIVER_DEBUG_VERBOSE(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_VERBOSE)) { \
printk(KERN_INFO "[FIRMWARW_DRIVER_SYSFS][VER][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_DRIVER_DEBUG_ERROR(fmt, args...) do { \
if ((g_firmware_driver_debug) & (1U << FIRWMARE_ERROR)) { \
printk(KERN_ERR "[FIRMWARW_DRIVER_SYSFS][ERR][func:%s line:%d]\r\n"fmt, __func__, __LINE__, ## args); \
} \
} while (0)
#define FIRMWARE_NAME_LEN 48
#define FIRMWARE_FAILED (-1)
#define FIRMWARE_SUCCESS 0
/* ioctl publi command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_COMMON_TYPE 'C'
#define FIRMWARE_GET_CHIPNAME _IOR(FIRMWARE_COMMON_TYPE, 0, char) /* get the chip name */
#define FIRMWARE_GET_VERSION _IOR(FIRMWARE_COMMON_TYPE, 2, int) /* get version */
/* firmware sysfs driver ioctl command, the same as "firmware_upgrade\include\firmware_app.h" */
#define FIRMWARE_SYSFS_TYPE 'S'
#define FIRMWARE_SYSFS_INIT _IOR(FIRMWARE_SYSFS_TYPE, 0, char) /* enable upgrade access */
#define FIRMWARE_SYSFS_FINISH _IOR(FIRMWARE_SYSFS_TYPE, 1, char) /* disable upgrade access */
#define FIRMWARE_SYSFS_SPI_INFO _IOR(FIRMWARE_SYSFS_TYPE, 2, char) /* spi flash upgrade */
#define FIRMWARE_SYSFS_DEV_FILE_INFO _IOR(FIRMWARE_SYSFS_TYPE, 3, char) /* sysfs upgrade */
#define FIRMWARE_SYSFS_MTD_INFO _IOR(FIRMWARE_SYSFS_TYPE, 4, char) /* sysfs mtd upgrade */
#define FIRMWARE_SYSFS_TYPE_SPI_LOGIC "SPI_LOGIC"
#define FIRMWARE_SYSFS_TYPE_SYSFS "SYSFS"
#define FIRMWARE_SYSFS_TYPE_MTD "MTD_DEV"
typedef struct cmd_info_s {
uint32_t size;
void __user *data;
} cmd_info_t;
typedef struct firmware_device_s {
struct list_head list; /* device list */
uint32_t chain; /* chain number */
char name[FIRMWARE_NAME_LEN]; /* name */
struct miscdevice dev; /* device */
void *priv; /* private data */
} firmware_device_t;
typedef struct firmware_driver_s {
struct list_head list; /* list */
char name[FIRMWARE_NAME_LEN]; /* name */
struct platform_driver *drv; /* driver */
void *priv; /* private data */
} firmware_driver_t;
extern int g_firmware_driver_debug;
/* Get device information based on minor */
extern firmware_device_t *firmware_get_device_by_minor(int minor);
/* Registere device */
extern int firmware_device_register(firmware_device_t *fw_dev);
/* Unregister device */
extern void firmware_device_unregister(firmware_device_t *fw_dev);
/* Registere driver */
extern int firmware_driver_register(firmware_driver_t *fw_drv);
/* Unregister driver */
extern void firmware_driver_unregister(firmware_driver_t *fw_drv);
/* SYSFS upgrade initialized */
extern int firmware_sysfs_init(void);
/* SYSFS unload function */
extern void firmware_sysfs_exit(void);
#endif /* end of __FIRMWARE_SYSFS_H__ */

View File

@ -0,0 +1,72 @@
#ifndef __FIRMWARE_SYSFS_UPGRADE_H__
#define __FIRMWARE_SYSFS_UPGRADE_H__
#define FIRMWARE_DEV_NAME_LEN 64 /* the macro definition needs to same as app space define */
#define FIRMWARE_TYPE_LEN 10
#define FIRMWARE_EN_INFO_MAX 16
typedef struct firmware_spi_logic_info_s {
char dev_name[FIRMWARE_DEV_NAME_LEN]; /* Logical device name */
uint32_t flash_base; /* Flash Upgrade Address */
uint32_t ctrl_base; /* SPI upgrade control register base address */
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
} firmware_spi_logic_info_t;
typedef struct firmware_dev_file_info_s {
char sysfs_name[FIRMWARE_DEV_NAME_LEN]; /* sysfs name */
uint32_t dev_base; /* device upgrade base address */
uint32_t per_len; /* The length of bytes per operation */
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
} firmware_dev_file_info_t;
typedef struct firmware_mtd_info_s {
char mtd_name[FIRMWARE_DEV_NAME_LEN]; /* sysfs name */
uint32_t flash_base; /* Flash Upgrade Address */
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
} firmware_mtd_info_t;
typedef struct firmware_gpio_jtag_en_s {
uint32_t en_gpio; /* GPIO enable pin */
uint32_t en_level; /* GPIO enable level */
int flag; /* init flag; 1-init 0-not init */
} firmware_gpio_jtag_en_t;
typedef struct firmware_logic_dev_en_s {
char dev_name[FIRMWARE_DEV_NAME_LEN]; /* Logical device name */
uint32_t addr; /* Enable register address */
uint32_t mask; /* mask */
uint32_t en_val; /* Enable value */
uint32_t dis_val; /* Disable value*/
uint32_t width; /* width */
int flag; /* init flag; 1-init 0-not init */
} firmware_logic_dev_en_t;
typedef struct firmware_sysfs_s {
char devname[FIRMWARE_DEV_NAME_LEN]; /* Device name */
char type[FIRMWARE_TYPE_LEN]; /* interface type */
uint32_t chain; /* chain num */
uint32_t chip_index; /* chip index */
union {
firmware_spi_logic_info_t spi_logic_info; /* SPI logic Information */
firmware_dev_file_info_t dev_file_info; /* device file Information */
firmware_mtd_info_t mtd_info; /* mtd device Information */
} info;
uint32_t gpio_en_info_num; /* GPIO Enable Number */
firmware_gpio_jtag_en_t gpio_en_info[FIRMWARE_EN_INFO_MAX]; /* GPIO Enable Information */
uint32_t logic_dev_en_num; /* Register Enable Number */
firmware_logic_dev_en_t logic_dev_en_info[FIRMWARE_EN_INFO_MAX]; /* Register Enable Information */
} firmware_sysfs_t;
typedef struct firmware_sysfs_function_s{
int (*init_dev)(void); /* upgrade initializes the operation */
int (*finish_dev)(void); /* upgrade completes the operation */
}firmware_sysfs_function_t;
extern void firmware_set_sysfs_info(firmware_sysfs_t *sysfs_info);
extern int firmware_init_dev_loc(firmware_sysfs_t *sysfs_info);
extern int firmware_finish_dev_loc(firmware_sysfs_t *sysfs_info);
#endif /* __FIRMWARE_SYSFS_UPGRADE_H__ */

View File

@ -0,0 +1,57 @@
#ifndef __FIRMWARE_UPGRADE_H__
#define __FIRMWARE_UPGRADE_H__
#include <linux/string.h>
#define TYPE_LEN (10)
#define DEV_NAME_LEN (64)
#define ENABLE_NUM (16)
#define mem_clear(data, size) memset((data), 0, (size))
typedef struct firmware_jtag_device_s {
uint32_t tdi;
uint32_t tck;
uint32_t tms;
uint32_t tdo;
uint32_t tck_delay;
} firmware_jtag_device_t;
typedef struct firmware_sysfs_device_s {
uint32_t test_base;
uint32_t test_size;
char dev_name[DEV_NAME_LEN];
uint32_t flash_base;
uint32_t ctrl_base;
char sysfs_name[DEV_NAME_LEN];
uint32_t dev_base;
uint32_t per_len;
char mtd_name[DEV_NAME_LEN];
} firmware_sysfs_device_t;
typedef struct firmware_upgrade_device_s {
char type[TYPE_LEN];
uint32_t chain;
uint32_t chip_index;
uint32_t en_gpio_num; /* the number of en_gpio */
uint32_t en_gpio[ENABLE_NUM];
uint32_t en_level[ENABLE_NUM];
uint32_t en_logic_num; /* the number of en_logic */
char en_logic_dev[ENABLE_NUM][DEV_NAME_LEN];
uint32_t en_logic_addr[ENABLE_NUM];
uint32_t en_logic_mask[ENABLE_NUM];
uint32_t en_logic_en_val[ENABLE_NUM];
uint32_t en_logic_dis_val[ENABLE_NUM];
uint32_t en_logic_width[ENABLE_NUM];
int device_flag;
union {
firmware_jtag_device_t jtag;
firmware_sysfs_device_t sysfs;
} upg_type;
} firmware_upgrade_device_t;
#endif

View File

@ -0,0 +1,33 @@
include $(top_srcdir)/Rules.mk
#OBJ = firmware_app.o debug.o hardware.o ispvm_ui.o ivm_core.o crc32.o
PWD = $(shell pwd)
SRC :=
SRC += $(shell find $(PWD) -name '*.c')
OBJ := $(SRC:%.c=%.o)
LIB += $(BUILD_CFALGS) $(BUILD_LDFLAGS) -lpthread -lreadline -lncurses
INCLUDE = -Iinclude
INCLUDE+= -Wall
APP = firmware_upgrade
ELF_FILE = $(APP)
MAP_FILE = $(APP).map.sym
.PHONY: build
build:$(OBJ)
$(CC) $^ -o $(ELF_FILE) $(LINKFLAGS) $(LIB)
$(NM) $(ELF_FILE) | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' \
| sort > $(MAP_FILE)
cp -p $(ELF_FILE) $(common_out_put_dir)
%.o:%.c
$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@
.PHONY: install
install:
echo "firmware_upgrade install success."
cp -p $(ELF_FILE) $(common_out_put_dir)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)

View File

@ -0,0 +1,216 @@
/*
* This file is derived from crc32.c from the zlib-1.1.3 distribution
* by Jean-loup Gailly and Mark Adler.
*/
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-1998 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* xxxx: by chihl for compile error */
#if 1
#ifndef FAR
#define FAR
#endif
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte FAR Bytef;
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifndef OF /* function prototypes */
#ifdef STDC
#define OF(args) args
#else
#define OF(args) ()
#endif
#endif
#endif
#define local static
#define ZEXPORT /* empty */
unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
#define DYNAMIC_CRC_TABLE
#ifdef DYNAMIC_CRC_TABLE
local int crc_table_empty = 1;
local uLongf crc_table[256];
local void make_crc_table OF((void));
/*
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The table is simply the CRC of all possible eight bit values. This is all
the information needed to generate CRC's on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
local void make_crc_table()
{
uLong c;
int n, k;
uLong poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++)
{
c = (uLong)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
}
crc_table_empty = 0;
}
#else
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by make_crc_table)
*/
local const uLongf crc_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
#endif
#if 0
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const uLongf * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) make_crc_table();
#endif
return (const uLongf *)crc_table;
}
#endif
/* ========================================================================= */
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
#define DO2(buf) DO1(buf); DO1(buf);
#define DO4(buf) DO2(buf); DO2(buf);
#define DO8(buf) DO4(buf); DO4(buf);
/* ========================================================================= */
uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len)
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8(buf);
len -= 8;
}
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}
#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
/* No ones complement version. JFFS2 (and other things ?)
* don't use ones compliment in their CRC calculations.
*/
uLong ZEXPORT crc32_no_comp(uLong crc, const Bytef *buf, uInt len)
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif
while (len >= 8)
{
DO8(buf);
len -= 8;
}
if (len) do {
DO1(buf);
} while (--len);
return crc;
}
#endif /* CFG_CMD_JFFS2 */

View File

@ -0,0 +1,60 @@
/*
* debug.c
* firmware upgrade debug switch control
*/
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <ctype.h>
#include <debug.h>
int is_debug_on = DEBUG_IGNORE;
/*
* firmware_upgrade_debug
* function: Debug switch
* Parses the file "/var/tmp/.firmware_upgrade_debug" and returns the corresponding debug level
* return:off--DEBUG_OFF, app debug on---DEBUG_APP_ON, kernel debug on--DEBUG_KERN_ON,
* all debug on--DEBUG_ALL_ON, other--DEBUG_IGNORE
*/
int firmware_upgrade_debug(void)
{
int size;
FILE *fp;
char debug_info[DEBUG_INFO_LEN];
fp = fopen(DEBUG_FILE, "r");
if (fp == NULL) {
return DEBUG_IGNORE;
}
mem_clear(debug_info, DEBUG_INFO_LEN);
size = fread(debug_info, DEBUG_INFO_LEN - 1, 1, fp);
if (size < 0) {
fclose(fp);
return DEBUG_IGNORE;
}
if (strncmp(debug_info, DEBUG_ON_INFO, 1) == 0) {
fclose(fp);
return DEBUG_APP_ON;
}
if (strncmp(debug_info, DEBUG_ON_ALL, 1) == 0) {
fclose(fp);
return DEBUG_ALL_ON;
}
if (strncmp(debug_info, DEBUG_OFF_INFO, 1) == 0) {
fclose(fp);
return DEBUG_OFF;
}
fclose(fp);
return DEBUG_IGNORE;
}

View File

@ -0,0 +1,985 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <linux/version.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <firmware_app.h>
int header_offset;
static firmware_file_name_t firmware_file_str[] = {
{"VME", FIRMWARE_VME},
{"ISC", FIRMWARE_ISC},
{"JBI", FIRMWARE_JBI},
{"SPI-LOGIC-DEV", FIRMWARE_SPI_LOGIC_DEV},
{"SYSFS", FIRMWARE_SYSFS_DEV},
{"MTD", FIRMWARE_MTD},
};
/**
* firmware_error_type
* function:set error code
* @action: param[in] The stage where the error occurs
* @info: param[in] Upgrade file information
* return value: error code
*/
int firmware_error_type(int action, name_info_t *info)
{
if (info == NULL) {
return ERR_FW_UPGRADE;
}
if((info->type <= FIRMWARE_UNDEF_TYPE) || (info->type > FIRMWARE_OTHER)) {
return ERR_FW_UPGRADE;
}
if (info->type == FIRMWARE_CPLD) {
switch (action) {
case FIRMWARE_ACTION_CHECK:
return ERR_FW_CHECK_CPLD_UPGRADE;
case FIRMWARE_ACTION_MATCH:
return ERR_FW_MATCH_CPLD_UPGRADE;
case FIRMWARE_ACTION_VERCHECK:
return ERR_FW_SAMEVER_CPLD_UPGRADE;
case FIRMWARE_ACTION_UPGRADE:
return ERR_FW_DO_CPLD_UPGRADE;
case FIRMWARE_ACTION_SUPPORT:
return ERR_FW_DO_UPGRADE_NOT_SUPPORT;
default:
return ERR_FW_UPGRADE;
}
} else if (info->type == FIRMWARE_FPGA) {
switch (action) {
case FIRMWARE_ACTION_CHECK:
return ERR_FW_CHECK_FPGA_UPGRADE;
case FIRMWARE_ACTION_MATCH:
return ERR_FW_MATCH_FPGA_UPGRADE;
case FIRMWARE_ACTION_VERCHECK:
return ERR_FW_SAMEVER_FPGA_UPGRADE;
case FIRMWARE_ACTION_UPGRADE:
return ERR_FW_DO_FPGA_UPGRADE;
case FIRMWARE_ACTION_SUPPORT:
return ERR_FW_DO_UPGRADE_NOT_SUPPORT;
default:
return ERR_FW_UPGRADE;
}
} else {
switch (action) {
case FIRMWARE_ACTION_CHECK:
return ERR_FW_CHECK_UPGRADE;
case FIRMWARE_ACTION_MATCH:
return ERR_FW_MATCH_UPGRADE;
case FIRMWARE_ACTION_VERCHECK:
return ERR_FW_SAMEVER_UPGRADE;
case FIRMWARE_ACTION_UPGRADE:
return ERR_FW_DO_UPGRADE;
case FIRMWARE_ACTION_SUPPORT:
return ERR_FW_DO_UPGRADE_NOT_SUPPORT;
default:
return ERR_FW_UPGRADE;
}
}
}
/*
* firmware_check_file_info
* function:Check the file information to determine that the file is available for use on the device
* @info: param[in] Upgrade file information
* @main_type : param[in] main type
* @sub_type : param[in] sub type
* @slot : param[in] 0--main, sub slot starts at 1
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_check_file_info(name_info_t *info, int main_type, int sub_type, int slot)
{
int i;
dbg_print(is_debug_on, "Check file info.\n");
/* Check the mainboard type */
for (i = 0; i < MAX_DEV_NUM; i++) {
if (main_type == info->card_type[i]) {
dbg_print(is_debug_on, "main type is 0x%x \n", main_type);
break;
}
}
if (i == MAX_DEV_NUM) {
dbg_print(is_debug_on, "Error: The main type[0x%x] is not matched \n", main_type);
return firmware_error_type(FIRMWARE_ACTION_MATCH, info);
}
/* Check the sub board type, if firwmare upgrade sub board, then sub_type must be 0 */
for (i = 0; i < MAX_DEV_NUM; i++) {
if (sub_type == info->sub_type[i]) {
dbg_print(is_debug_on, "sub type is 0x%x \n", sub_type);
break;
}
}
if (i == MAX_DEV_NUM) {
dbg_print(is_debug_on, "Error: The sub type[0x%x] is not matched \n", sub_type);
return firmware_error_type(FIRMWARE_ACTION_MATCH, info);
}
/* if firwmare upgrade main board, then sub_type must be 0 and slot must be 0
* if firwmare upgrade sub board, then sub_type must not be 0 and slot must not be 0 */
if (((sub_type != 0) && (slot < 1)) || ((sub_type == 0) && (slot != 0))) {
dbg_print(is_debug_on, "Error: The sub type[0x%x] is not match slot %d error.\n", sub_type, slot);
return firmware_error_type(FIRMWARE_ACTION_MATCH, info);
}
dbg_print(is_debug_on, "Success check file info.\n");
return FIRMWARE_SUCCESS;
}
/*
* firmware_get_dev_file_name
* function:Gets the name of the device file
* @info: param[in] Upgrade file information
* @len: param[in] Device file name length
* @file_name: param[out] Device file name
*/
static int firmware_get_dev_file_name(name_info_t *info, char *file_name, int len)
{
int ret;
ret = FIRMWARE_SUCCESS;
switch(info->file_type) {
case FIRMWARE_VME:
snprintf(file_name, len, "/dev/firmware_cpld_ispvme%d", info->chain);
break;
case FIRMWARE_ISC:
case FIRMWARE_JBI:
snprintf(file_name, len, "/dev/firmware_cpld%d", info->chain);
break;
case FIRMWARE_SPI_LOGIC_DEV:
case FIRMWARE_SYSFS_DEV:
case FIRMWARE_MTD:
snprintf(file_name, len, "/dev/firmware_sysfs%d", info->chain);
break;
default:
ret = FIRMWARE_FAILED;
break;
}
return ret;
}
/**
* firmware_check_chip_verison
* function: Check chip version
* @fd: param[in] Device file descriptor
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
int firmware_check_chip_verison(int fd, name_info_t *info)
{
int ret;
cmd_info_t cmd_info;
char version[FIRMWARE_NAME_LEN + 1];
dbg_print(is_debug_on, "Check chip version.\n");
mem_clear(version, FIRMWARE_NAME_LEN);
cmd_info.size = FIRMWARE_NAME_LEN;
cmd_info.data = (void *) version;
/* Ignore version checking */
if (strncmp("v", info->version, 1) == 0) {
dbg_print(is_debug_on, "Skip check chip version.\n");
return FIRMWARE_SUCCESS;
}
/* Get the program version from the device file */
ret = ioctl(fd, FIRMWARE_GET_VERSION, &cmd_info);
if (ret < 0) {
dbg_print(is_debug_on, "Error: Failed to get version(chain %d, version %s).\n",
info->chain, info->version);
return firmware_error_type(FIRMWARE_ACTION_CHECK, NULL);
}
dbg_print(is_debug_on, "Chip verion: %s, file chip verion: %s.\n", version, info->version);
/* The device version is the same and does not upgrade */
if (strcmp(version, info->version) == 0) {
dbg_print(is_debug_on, "the file program version is same as the firmware version %s \n",
info->version);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
dbg_print(is_debug_on, "Check version pass.\n");
return FIRMWARE_SUCCESS;
}
/*
* firmware_get_file_size
* function: Gets the upgrade file size
* @file_name: param[in] Upgrade file name
* @size: param[out] Upgrade file size
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int firmware_get_file_size(char *file_name, uint32_t *size)
{
int ret;
struct stat buf;
ret = stat(file_name, &buf);
if (ret < 0) {
return FIRMWARE_FAILED;
}
if (buf.st_size < 0 || buf.st_size - header_offset < 0) {
return FIRMWARE_FAILED;
}
/* Remove the upgrade file header information to actually upgrade the content size */
*size = buf.st_size - header_offset;
return FIRMWARE_SUCCESS;
}
/*
* firmware_get_file_info
* function: Gets the contents of the upgrade file
* @file_name: param[in] Upgrade file name
* @size: param[in] Upgrade file size
* @buf: param[out] Upgrade the file content
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int firmware_get_file_info(char *file_name, uint8_t *buf, uint32_t size)
{
FILE *fp;
int len;
int ret;
fp = fopen(file_name, "r");
if (fp == NULL) {
return FIRMWARE_FAILED;
}
/* Removes the contents of the upgrade file header information */
ret = fseek(fp, header_offset, SEEK_SET);
if (ret < 0) {
fclose(fp);
return FIRMWARE_FAILED;
}
len = fread(buf, size, 1, fp);
if (len < 0) {
fclose(fp);
return FIRMWARE_FAILED;
}
fclose(fp);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade
* function: firmware upgrade
* @file_name: param[in] Upgrade file name
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade(char *file_name, name_info_t *info)
{
int ret;
int fd;
uint32_t upg_size;
uint8_t *upg_buf;
char dev_file_name[FIRMWARE_NAME_LEN];
unsigned long crc;
dbg_print(is_debug_on, "Upgrade firmware: %s.\n", file_name);
mem_clear(dev_file_name, FIRMWARE_NAME_LEN);
ret = firmware_get_dev_file_name(info, dev_file_name, FIRMWARE_NAME_LEN - 1);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to get dev file name.\n");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
fd = open(dev_file_name, O_RDWR);
if (fd < 0) {
dbg_print(is_debug_on, "Error: Failed to open %s.\n", dev_file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
#if 0
/* check chip name */
ret = firmware_check_chip_name(fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip name: %s.\n", dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
#endif
/* Check chip version */
ret = firmware_check_chip_verison(fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip version: %s.\n", dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* Gets the upgrade file size */
ret = firmware_get_file_size(file_name, &upg_size);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to get file size: %s.\n", file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if (upg_size == 0) {
dbg_print(is_debug_on, "Error: The upgrade file is empty \n");
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
upg_buf = (uint8_t *) malloc(upg_size + 1);
if (upg_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for upgrade file info: %s.\n",
dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* Gets the contents of the upgrade file */
mem_clear(upg_buf, upg_size + 1);
ret = firmware_get_file_info(file_name, upg_buf, upg_size);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to read file info: %s.\n", file_name);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* file crc32 check */
crc = crc32(0, (const unsigned char *)upg_buf, (unsigned int)upg_size);
if (crc != info->crc32) {
dbg_print(is_debug_on, "Error: Failed to check file crc: %s.\n", file_name);
dbg_print(is_debug_on, "the crc value is : %#08x.\n", (unsigned int)crc);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
dbg_print(is_debug_on, "Start upgrading firmware, wait...\n");
/* Start firmware upgrade */
switch (info->file_type) {
case FIRMWARE_VME:
dbg_print(is_debug_on, "start to ispvme upgrade: %s.\n", file_name);
ret = firmware_upgrade_ispvme(fd, file_name, info);
break;
case FIRMWARE_ISC:
case FIRMWARE_JBI:
dbg_print(is_debug_on, "start to upgrade: %s.\n", file_name);
ret = firmware_upgrade_jtag(fd, upg_buf, upg_size, info);
break;
case FIRMWARE_SPI_LOGIC_DEV:
dbg_print(is_debug_on, "start to spi logic dev upgrade: %s.\n", file_name);
ret = firmware_upgrade_spi_logic_dev(fd, upg_buf, upg_size, info);
break;
case FIRMWARE_SYSFS_DEV:
dbg_print(is_debug_on, "start to sysfs upgrade: %s.\n", file_name);
ret = firmware_upgrade_sysfs(fd, upg_buf, upg_size, info);
break;
case FIRMWARE_MTD:
dbg_print(is_debug_on, "start to mtd device upgrade: %s.\n", file_name);
ret = firmware_upgrade_mtd(fd, upg_buf, upg_size, info);
break;
default:
dbg_print(is_debug_on, "Error: file type is not support: %s.\n", file_name);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_UPGRADE, info);
}
dbg_print(is_debug_on, "Completed.\n");
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to upgrade: %s.\n", dev_file_name);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_UPGRADE, info);
}
free(upg_buf);
close(fd);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_test
* function: firmware upgrade test
* @file_name: param[in] Upgrade file name
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_test(char *file_name, name_info_t *info)
{
int ret;
int fd;
uint32_t upg_size;
uint8_t *upg_buf;
char dev_file_name[FIRMWARE_NAME_LEN];
unsigned long crc;
dbg_print(is_debug_on, "Upgrade firmware test: %s.\n", file_name);
mem_clear(dev_file_name, FIRMWARE_NAME_LEN);
ret = firmware_get_dev_file_name(info, dev_file_name, FIRMWARE_NAME_LEN - 1);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to get dev file name.\n");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
fd = open(dev_file_name, O_RDWR);
if (fd < 0) {
dbg_print(is_debug_on, "Error: Failed to open %s.\n", dev_file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
#if 0
/* check chip name */
ret = firmware_check_chip_name(fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip name: %s.\n", dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
#endif
/* Check chip version */
ret = firmware_check_chip_verison(fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip version: %s.\n", dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* Gets the upgrade file size */
ret = firmware_get_file_size(file_name, &upg_size);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to get file size: %s.\n", file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
upg_buf = (uint8_t *) malloc(upg_size + 1);
if (upg_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for upgrade file info: %s.\n",
dev_file_name);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* Gets the contents of the upgrade file */
mem_clear(upg_buf, upg_size + 1);
ret = firmware_get_file_info(file_name, upg_buf, upg_size);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to read file info: %s.\n", file_name);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
/* file crc32 check */
crc = crc32(0, (const unsigned char *)upg_buf, (unsigned int)upg_size);
if (crc != info->crc32) {
dbg_print(is_debug_on, "Error: Failed to check file crc: %s.\n", file_name);
dbg_print(is_debug_on, "the crc value is : %#08x.\n", (unsigned int)crc);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
dbg_print(is_debug_on, "Start upgrading firmware test, wait...\n");
/* Start firmware upgrade */
switch (info->file_type) {
case FIRMWARE_VME:
dbg_print(is_debug_on, "start to ispvme upgrade test: %s.\n", file_name);
/* WME upgrade link testing is the same as upgrading, using vme test file. */
ret = firmware_upgrade_ispvme(fd, file_name, info);
break;
case FIRMWARE_ISC:
case FIRMWARE_JBI:
dbg_print(is_debug_on, "start to upgrade test: %s.\n", file_name);
ret = firmware_upgrade_jtag_test(fd, upg_buf, upg_size, info);
break;
case FIRMWARE_SPI_LOGIC_DEV:
dbg_print(is_debug_on, "start to spi logic dev upgrade test: %s.\n", file_name);
ret = firmware_upgrade_spi_logic_dev_test(fd,info);
break;
case FIRMWARE_SYSFS_DEV:
dbg_print(is_debug_on, "start to sysfs upgrade test: %s.\n", file_name);
ret = firmware_upgrade_sysfs_test(fd, info);
break;
case FIRMWARE_MTD:
dbg_print(is_debug_on, "start to mtd device upgrade test: %s.\n", file_name);
ret = firmware_upgrade_mtd_test(fd, info);
break;
default:
dbg_print(is_debug_on, "Error: test file type is not support: %s.\n", file_name);
free(upg_buf);
close(fd);
return firmware_error_type(FIRMWARE_ACTION_UPGRADE, info);
}
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to upgrade test: %s ret=%d.\n", dev_file_name, ret);
free(upg_buf);
close(fd);
if (ret == FIRMWARE_NOT_SUPPORT) {
return firmware_error_type(FIRMWARE_ACTION_SUPPORT, info);
} else {
return firmware_error_type(FIRMWARE_ACTION_UPGRADE, info);
}
}
free(upg_buf);
close(fd);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_file_type_map
* function:Gets the corresponding upgrade file type from the upgrade file type list
* @value : param[in] file type name
* return value : file type, firmware_file_type_t
*/
static firmware_file_type_t firmware_upgrade_file_type_map(char *type_str)
{
int type_num;
int i;
type_num = (sizeof(firmware_file_str) /sizeof(firmware_file_str[0]));
for (i = 0; i < type_num; i++) {
if (!strncmp(firmware_file_str[i].firmware_file_name_str, type_str,
strlen(firmware_file_str[i].firmware_file_name_str))) {
return firmware_file_str[i].firmware_file_type;
}
}
dbg_print(is_debug_on, "firmware file type unknown\n");
return FIRMWARE_NONE;
}
/*
* firmware_upgrade_parse_kv
* function:Parses the header information of the upgrade file based on the key and value
* @key: param[in] key
* @value : param[in] value
* @info : param[out] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_parse_kv(const char *key, const char *value, name_info_t *info)
{
int i;
if (key == NULL || value == NULL) {
dbg_print(is_debug_on, "Error: failed to get ther key or value.\n");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
} else if (strcmp(key, FILEHEADER_DEVTYPE) == 0) {
/* main board type */
for (i = 0; i < MAX_DEV_NUM && info->card_type[i]; i++);
if (i == MAX_DEV_NUM) {
dbg_print(is_debug_on, "Error: card type is full for %s. \n", value);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
info->card_type[i] = strtoul(value, NULL, 0);
} else if (strcmp(key, FILEHEADER_SUBTYPE) == 0) {
/* sub board type */
for (i = 0; i < MAX_DEV_NUM && info->sub_type[i]; i++);
if (i == MAX_DEV_NUM) {
dbg_print(is_debug_on, "Error: sub type is full for %s. \n", value);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
info->sub_type[i] = strtoul(value, NULL, 0);
} else if (strcmp(key, FILEHEADER_TYPE) == 0) {
/* Device type */
if (strcmp(value, FIRMWARE_CPLD_NAME) == 0) {
info->type = FIRMWARE_CPLD;
} else if (strcmp(value, FIRMWARE_FPGA_NAME) == 0) {
info->type = FIRMWARE_FPGA;
} else {
info->type = FIRMWARE_OTHER;
}
} else if (strcmp(key, FILEHEADER_CHAIN) == 0) {
/* link num */
info->chain = strtoul(value, NULL, 10);
} else if (strcmp(key, FILEHEADER_CHIPNAME) == 0) {
/* chip name */
if (strlen(value) >= FIRMWARE_NAME_LEN) {
dbg_print(is_debug_on, "Error: '%s' is too long for a chipname.\n", value);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
mem_clear(info->chip_name, sizeof(info->chip_name));
snprintf(info->chip_name, sizeof(info->chip_name) - 1, "%s", value);
} else if (strcmp(key, FILEHEADER_VERSION) == 0) {
/* version */
if (strlen(value) >= FIRMWARE_NAME_LEN) {
dbg_print(is_debug_on, "Error: '%s' is too long for a version.\n", value);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
mem_clear(info->version, sizeof(info->version));
snprintf(info->version, sizeof(info->version) - 1, "%s", value);
} else if (strcmp(key, FILEHEADER_FILETYPE) == 0) {
/* file type */
info->file_type = firmware_upgrade_file_type_map((char *)value);
} else if (strcmp(key, FILEHEADER_CRC) == 0) {
/* file crc32 */
info->crc32 = strtoul(value, NULL, 0);
} else {
dbg_print(is_debug_on, "Warning: key '%s' is unknown. Continue anyway.\n", key);
return FIRMWARE_SUCCESS;
}
dbg_print(is_debug_on, "key %s is matched.\n", key);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_parse_check
* function:Check the results of header parsing
* @file_name: Upgrade file name
* @info : Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_parse_check(char *file_name, name_info_t *info)
{
int i;
if (info->card_type[0] == 0) {
dbg_print(is_debug_on, "Error: %s card type is missing.\n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if ((info->type <= FIRMWARE_UNDEF_TYPE) || (info->type > FIRMWARE_OTHER)) {
dbg_print(is_debug_on, "Error: %s type is unknown.\n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if (strlen(info->chip_name) == 0) {
dbg_print(is_debug_on, "Error: %s chip_name is empty.\n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if (strlen(info->version) == 0) {
dbg_print(is_debug_on, "Error: %s version is empty.\n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if ((info->file_type <= FIRMWARE_UNDEF_FILE_TYPE) || (info->file_type > FIRMWARE_NONE)) {
dbg_print(is_debug_on, "Error: %s file type is unknown.\n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
dbg_print(is_debug_on, "The file header parse:(%s) \n" , file_name);
dbg_print(is_debug_on, " card type: ");
for (i = 0; i < MAX_DEV_NUM && info->card_type[i]; i++){
dbg_print(is_debug_on, "0x%x, ", info->card_type[i]);
}
dbg_print(is_debug_on, "\n"
" sub type : ");
for (i = 0; i < MAX_DEV_NUM && info->sub_type[i]; i++){
dbg_print(is_debug_on, "0x%x, ", info->sub_type[i]);
}
dbg_print(is_debug_on, "\n"
" type : %d, \n"
" chain : %d, \n"
" chip name: %s \n"
" version : %s \n"
" file type: %d \n"
" the crc32 value: %#x \n",
info->type, info->chain, info->chip_name, info->version, info->file_type, info->crc32);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_read_header
* function:Read the header information of the upgrade file
* @file_name: param[in] Upgrade file name
* @info : param[out] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_read_header( char *file_name, name_info_t *info)
{
FILE *fp;
char *charp;
char *charn;
char header_buffer[MAX_HEADER_SIZE];
char header_key[MAX_HEADER_KV_SIZE];
char header_var[MAX_HEADER_KV_SIZE];
int ret;
int len;
fp = fopen(file_name, "r");
if (fp == NULL) {
dbg_print(is_debug_on, "Error: Failed to open file: %s. \n", file_name);
perror("fopen");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
mem_clear(header_buffer, sizeof(header_buffer));
len = fread(header_buffer, MAX_HEADER_SIZE - 1, 1, fp);
fclose(fp);
if (len < 0) {
dbg_print(is_debug_on, "Error: Failed to read header : %s. \n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
header_buffer[MAX_HEADER_SIZE - 1] = 0;
charp = strstr(header_buffer, "FILEHEADER(\n");
if (charp == NULL) {
dbg_print(is_debug_on, "Error: The file format %s is wrong. \n", file_name);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
charp += strlen("FILEHEADER(\n");
dbg_print(is_debug_on, "File parse start.\n");
mem_clear(info, sizeof(name_info_t));
ret = 0;
charn = charp;
mem_clear(header_key, sizeof(header_key));
while (*charn != ')') {
charn = strpbrk(charp, "=,)\n");
if (charn == NULL) {
dbg_print(is_debug_on, "Error: The parser can't find mark.\n");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
if (charn - charp >= MAX_HEADER_KV_SIZE) {
dbg_print(is_debug_on, "Error: The parser find a overflow mark.\n");
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
switch (*charn) {
case '=':
mem_clear(header_key, sizeof(header_key));
memcpy(header_key, charp, charn - charp);
break;
case '\n':
case ',':
mem_clear(header_var, sizeof(header_var));
memcpy(header_var, charp, charn - charp);
dbg_print(is_debug_on, "Parser: %s = %s .\n", header_key, header_var);
firmware_upgrade_parse_kv(header_key, header_var, info);
break;
case ')':
break;
default:
dbg_print(is_debug_on, "Error: The parser get unexpected mark '%c(0x%02X)'.\n", *charn, *charn);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
charp = (charn + 1);
}
ret = firmware_upgrade_parse_check(file_name, info);
if (ret != FIRMWARE_SUCCESS) {
return FIRMWARE_FAILED;
}
header_offset = charp + 1 - header_buffer; /* charp at '\n' */
dbg_print(is_debug_on,"the header offset is %d \n", header_offset);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_one_file
* function: upgrade file
* @file_name: Upgrade file name
* @main_type: main board type
* @sub_type: sub board type
* @slot: 0--main, sub slot starts at 1
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_one_file(char *file_name, int main_type, int sub_type, int slot)
{
int ret;
name_info_t info;
if ((slot < 0) || (file_name == NULL)) {
dbg_print(is_debug_on, "Failed firmware_upgrade_one_file parameter err.\n");
return FIRMWARE_FAILED;
}
dbg_print(is_debug_on, "firmware upgrade %s 0x%x 0x%x %d\n", file_name, main_type, sub_type, slot);
/* Read the header information of the upgrade file */
ret = firmware_upgrade_read_header(file_name, &info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to get file header: %s\n", file_name);
return ret;
}
/* Check the file information to determine that the file is available for use on the device */
ret = firmware_check_file_info(&info, main_type, sub_type, slot);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "File is not match with the device: %s.\n", file_name);
return ret;
}
/* The link number corresponding to the upgrade file is calculated based on the slot number.
16 links are reserved for each slot. main boade slot is 0. */
info.chain += slot * FIRMWARE_SLOT_MAX_NUM;
ret = firmware_upgrade(file_name, &info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to upgrade: %s.\n", file_name);
return ret;
}
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_file_test
* function: upgrade file
* @file_name: Upgrade file name
* @main_type: main board type
* @sub_type: sub board type
* @slot: 0--main, sub slot starts at 1
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
static int firmware_upgrade_file_test(char *file_name, int main_type, int sub_type, int slot)
{
int ret;
name_info_t info;
if ((slot < 0) || (file_name == NULL)) {
dbg_print(is_debug_on, "Failed firmware_upgrade_one_file parameter err.\n");
return FIRMWARE_FAILED;
}
dbg_print(is_debug_on, "firmware upgrade %s 0x%x 0x%x %d\n", file_name, main_type, sub_type, slot);
/* Read the header information of the upgrade file */
ret = firmware_upgrade_read_header(file_name, &info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to get file header: %s, ret=%d\n", file_name, ret);
return ret;
}
/* Check the file information to determine that the file is available for use on the device */
ret = firmware_check_file_info(&info, main_type, sub_type, slot);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "File is not match with the device: %s, ret=%d.\n", file_name, ret);
return ret;
}
/* The link number corresponding to the upgrade file is calculated based on the slot number.
16 links are reserved for each slot. main boade slot is 0. */
info.chain += slot * FIRMWARE_SLOT_MAX_NUM;
ret = firmware_upgrade_test(file_name, &info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to upgrade: %s, ret=%d\n", file_name, ret);
return ret;
}
return FIRMWARE_SUCCESS;
}
static int firmware_upgrade_data_dump(char *argv[])
{
int ret;
uint32_t offset, len;
/* dump by type */
if (strcmp(argv[2], "spi_logic_dev") == 0) {
/* usag: firmware_upgrade dump spi_logic_dev dev_path offset size print/record_file_path */
offset = strtoul(argv[4], NULL, 0);
len = strtoul(argv[5], NULL, 0);
/* offset needs align by 256 bytes */
if ((offset & 0xff) || (len == 0)) {
dbg_print(is_debug_on,"only support offset align by 256 bytes.\n");
return FIRMWARE_FAILED;
}
dbg_print(is_debug_on, "start to dump %s data. offset:0x%x, len:0x%x\n", argv[2], offset, len);
ret = firmware_upgrade_spi_logic_dev_dump(argv[3], offset, len, argv[6]);
} else {
dbg_print(is_debug_on, "Error: %s not support dump data.\n", argv[2]);
return FIRMWARE_FAILED;
}
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to dump %s data. ret:%d\n", argv[3], ret);
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}
int main(int argc, char *argv[])
{
int ret;
int main_type, sub_type, slot;
is_debug_on = firmware_upgrade_debug();
signal(SIGTERM, SIG_IGN); /* ignore kill signal */
signal(SIGINT, SIG_IGN); /* ignore ctrl+c signal */
signal(SIGTSTP, SIG_IGN); /* ignore ctrl+z signal */
if ((argc != 5) && (argc != 6) && (argc != 7)) {
printf("Use:\n");
printf(" upgrade file : firmware_upgrade file main_type sub_type slot\n");
printf(" upgrade test : firmware_upgrade test file main_type sub_type slot\n");
printf(" spi_logic_dev dump : firmware_upgrade dump spi_logic_dev dev_path offset size print/record_file_path\n");
dbg_print(is_debug_on, "Failed to upgrade the number of argv: %d.\n", argc);
return ERR_FW_UPGRADE;
}
if (argc == 5) {
main_type = strtoul(argv[2], NULL, 16);
sub_type = strtoul(argv[3], NULL, 16);
slot = strtoul(argv[4], NULL, 10);
printf("+================================+\n");
printf("|Begin to upgrade, please wait...|\n");
ret = firmware_upgrade_one_file(argv[1], main_type, sub_type, slot);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Failed to upgrade a firmware file: %s. (%d)\n", argv[1], ret);
printf("| Upgrade failed! |\n");
printf("+================================+\n");
return ret;
}
printf("| Upgrade succeeded! |\n");
printf("+================================+\n");
dbg_print(is_debug_on, "Sucess to upgrade a firmware file: %s.\n", argv[1]);
return FIRMWARE_SUCCESS;
} else if ((argc == 6) && (strcmp(argv[1], "test") == 0)) {
main_type = strtoul(argv[3], NULL, 16);
sub_type = strtoul(argv[4], NULL, 16);
slot = strtoul(argv[5], NULL, 10);
printf("+=====================================+\n");
printf("|Begin to upgrade test, please wait...|\n");
ret = firmware_upgrade_file_test(argv[2], main_type, sub_type, slot);
if (ret == FIRMWARE_SUCCESS) {
printf("| Upgrade test succeeded! |\n");
printf("+=====================================+\n");
dbg_print(is_debug_on, "Sucess to upgrade test a firmware file: %s.\n", argv[2]);
return FIRMWARE_SUCCESS;
} else if (ret == ERR_FW_DO_UPGRADE_NOT_SUPPORT) {
dbg_print(is_debug_on, "do not support to upgrade test a firmware file: %s. (%d)\n", argv[2], ret);
printf("| Not support to upgrade test! |\n");
printf("+=====================================+\n");
return ret;
} else {
dbg_print(is_debug_on, "Failed to upgrade test a firmware file: %s. (%d)\n", argv[2], ret);
printf("| Upgrade test failed! |\n");
printf("+=====================================+\n");
return ret;
}
} else if (strcmp(argv[1], "dump") == 0) {
/* print device data */
ret = firmware_upgrade_data_dump(argv);
if (ret == FIRMWARE_SUCCESS) {
printf("dump data succeeded.\n");
return FIRMWARE_SUCCESS;
} else {
printf("dump data failed. ret:%d\n", ret);
return ret;
}
}
printf("+=================+\n");
printf("| UPGRADE FAIL! |\n");
printf("+=================+\n");
return ERR_FW_UPGRADE;
}

View File

@ -0,0 +1,263 @@
/*********************************************************************************
* Lattice Semiconductor Corp. Copyright 2000-2008
*
* This is the hardware.c of ispVME V12.1 for JTAG programmable devices.
* All the functions requiring customization are organized into this file for
* the convinience of porting.
*********************************************************************************/
/*********************************************************************************
* Revision History:
*
* 09/11/07 NN Type cast mismatch variables
* 09/24/07 NN Added calibration function.
* Calibration will help to determine the system clock frequency
* and the count value for one micro-second delay of the target
* specific hardware.
* Modified the ispVMDelay function
* Removed Delay Percent support
* Moved the sclock() function from ivm_core.c to hardware.c
*********************************************************************************/
#include <stdint.h>
#include <linux/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <firmware_app.h>
#include <time.h>
/********************************************************************************
* Declaration of global variables
*
*********************************************************************************/
unsigned char g_siIspPins = 0x00; /*Keeper of JTAG pin state*/
unsigned short g_usInPort = 0x379; /*Address of the TDO pin*/
unsigned short g_usOutPort = 0x378; /*Address of TDI, TMS, TCK pin*/
unsigned short g_usCpu_Frequency = 1000; /*Enter your CPU frequency here, unit in MHz.*/
/*********************************************************************************
* This is the definition of the bit locations of each respective
* signal in the global variable g_siIspPins.
*
* NOTE: Users must add their own implementation here to define
* the bit location of the signal to target their hardware.
* The example below is for the Lattice download cable on
* on the parallel port.
*
*********************************************************************************/
#if 0
const unsigned char g_ucPinTDI = JTAG_TDI; /* Bit address of TDI */
const unsigned char g_ucPinTCK = JTAG_TCK; /* Bit address of TCK */
const unsigned char g_ucPinTMS = JTAG_TMS; /* Bit address of TMS */
const unsigned char g_ucPinENABLE = JTAG_ENABLE; /* Bit address of ENABLE */
const unsigned char g_ucPinTRST = JTAG_TRST; /* Bit address of TRST */
const unsigned char g_ucPinTDO = JTAG_TDO; /* Bit address of TDO*/
#endif
int g_file_fd = -1;
/***************************************************************
*
* Functions declared in hardware.c module.
*
***************************************************************/
void writePort(unsigned char a_ucPins, unsigned char a_ucValue);
unsigned char readPort();
void sclock();
void ispVMDelay(unsigned short a_usTimeDelay);
void calibration(void);
/********************************************************************************
* writePort
* To apply the specified value to the pins indicated. This routine will
* be modified for specific systems.
* As an example, this code uses the IBM-PC standard Parallel port, along with the
* schematic shown in Lattice documentation, to apply the signals to the
* JTAG pins.
*
* PC Parallel port pin Signal name Port bit address
* 2 g_ucPinTDI 1
* 3 g_ucPinTCK 2
* 4 g_ucPinTMS 4
* 5 g_ucPinENABLE 8
* 6 g_ucPinTRST 16
* 10 g_ucPinTDO 64
*
* Parameters:
* - a_ucPins, which is actually a set of bit flags (defined above)
* that correspond to the bits of the data port. Each of the I/O port
* bits that drives an isp programming pin is assigned a flag
* (through a #define) corresponding to the signal it drives. To
* change the value of more than one pin at once, the flags are added
* together, much like file access flags are.
*
* The bit flags are only set if the pin is to be changed. Bits that
* do not have their flags set do not have their levels changed. The
* state of the port is always manintained in the static global
* variable g_siIspPins, so that each pin can be addressed individually
* without disturbing the others.
*
* - a_ucValue, which is either HIGH (0x01 ) or LOW (0x00 ). Only these two
* values are valid. Any non-zero number sets the pin(s) high.
*
*********************************************************************************/
void writePort(unsigned char a_ucPins, unsigned char a_ucValue)
{
switch (a_ucPins) {
case JTAG_TCK:
ioctl(g_file_fd, FIRMWARE_JTAG_TCK, &a_ucValue);
break;
case JTAG_TDI:
ioctl(g_file_fd, FIRMWARE_JTAG_TDI, &a_ucValue);
break;
case JTAG_TMS:
ioctl(g_file_fd, FIRMWARE_JTAG_TMS, &a_ucValue);
break;
case JTAG_ENABLE:
ioctl(g_file_fd, FIRMWARE_JTAG_EN, &a_ucValue);
break;
case JTAG_TRST:
//ioctl(g_file_fd, FIRMWARE_JTAG_TRST, &a_ucValue);
break;
default:
break;
}
}
/*********************************************************************************
*
* readPort
*
* Returns the value of the TDO from the device.
*
**********************************************************************************/
unsigned char readPort()
{
unsigned char ucRet = 0;
ioctl(g_file_fd, FIRMWARE_JTAG_TDO, &ucRet);
return (ucRet);
}
/*********************************************************************************
* sclock
*
* Apply a pulse to TCK.
*
* This function is located here so that users can modify to slow down TCK if
* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to
* 1, 2... to effectively slowing down TCK by half, quarter...
*
*********************************************************************************/
void sclock()
{
unsigned short IdleTime = 0; //change to > 0 if need to slow down TCK
unsigned short usIdleIndex = 0;
IdleTime++;
for (usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++) {
writePort(JTAG_TCK, 0x01);
}
for (usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++) {
writePort(JTAG_TCK, 0x00);
}
}
/********************************************************************************
*
* ispVMDelay
*
*
* Users must implement a delay to observe a_usTimeDelay, where
* bit 15 of the a_usTimeDelay defines the unit.
* 1 = milliseconds
* 0 = microseconds
* Example:
* a_usTimeDelay = 0x0001 = 1 microsecond delay.
* a_usTimeDelay = 0x8001 = 1 millisecond delay.
*
* This subroutine is called upon to provide a delay from 1 millisecond to a few
* hundreds milliseconds each time.
* It is understood that due to a_usTimeDelay is defined as unsigned short, a 16 bits
* integer, this function is restricted to produce a delay to 64000 micro-seconds
* or 32000 milli-second maximum. The VME file will never pass on to this function
* a delay time > those maximum number. If it needs more than those maximum, the VME
* file will launch the delay function several times to realize a larger delay time
* cummulatively.
* It is perfectly alright to provide a longer delay than required. It is not
* acceptable if the delay is shorter.
*
* Delay function example--using the machine clock signal of the native CPU------
* When porting ispVME to a native CPU environment, the speed of CPU or
* the system clock that drives the CPU is usually known.
* The speed or the time it takes for the native CPU to execute one for loop
* then can be calculated as follows:
* The for loop usually is compiled into the ASSEMBLY code as shown below:
* LOOP: DEC RA;
* JNZ LOOP;
* If each line of assembly code needs 4 machine cycles to execute,
* the total number of machine cycles to execute the loop is 2 x 4 = 8.
* Usually system clock = machine clock (the internal CPU clock).
* Note: Some CPU has a clock multiplier to double the system clock for
the machine clock.
*
* Let the machine clock frequency of the CPU be F, or 1 machine cycle = 1/F.
* The time it takes to execute one for loop = (1/F ) x 8.
* Or one micro-second = F(MHz)/8;
*
* Example: The CPU internal clock is set to 100Mhz, then one micro-second = 100/8 = 12
*
* The C code shown below can be used to create the milli-second accuracy.
* Users only need to enter the speed of the cpu.
*
**********************************************************************************/
void ispVMDelay(unsigned short a_usTimeDelay)
{
struct timespec ts;
if (a_usTimeDelay & 0x8000) {
/* milliseconds */
a_usTimeDelay &= 0x7FFF;
ts.tv_sec = (long int) (a_usTimeDelay / 1000);
ts.tv_nsec = (long int) (a_usTimeDelay % 1000) * 1000000ul;
} else {
/* microseconds */
ts.tv_sec = 0;
ts.tv_nsec = (long int) a_usTimeDelay * 1000ul;
}
nanosleep(&ts, NULL);
}
/*********************************************************************************
*
* calibration
*
* It is important to confirm if the delay function is indeed providing
* the accuracy required. Also one other important parameter needed
* checking is the clock frequency.
* Calibration will help to determine the system clock frequency
* and the loop_per_micro value for one micro-second delay of the target
* specific hardware.
*
**********************************************************************************/
void calibration(void)
{
/*Apply 2 pulses to TCK.*/
writePort(JTAG_TCK, 0x00);
writePort(JTAG_TCK, 0x01);
writePort(JTAG_TCK, 0x00);
writePort(JTAG_TCK, 0x01);
writePort(JTAG_TCK, 0x00);
/*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/
ispVMDelay(0x8001);
/*Apply 2 pulses to TCK*/
writePort(JTAG_TCK, 0x01);
writePort(JTAG_TCK, 0x00);
writePort(JTAG_TCK, 0x01);
writePort(JTAG_TCK, 0x00);
}

View File

@ -0,0 +1,837 @@
/**************************************************************
*
* Lattice Semiconductor Corp. Copyright 2008
*
* ispVME Embedded allows programming of Lattice's suite of FPGA
* devices on embedded systems through the JTAG port. The software
* is distributed in source code form and is open to re - distribution
* and modification where applicable.
*
* ispVME Embedded C Source comprised with 3 modules:
* ispvm_ui.c is the module provides input and output support.
* ivm_core.c is the module interpret the VME file(s).
* hardware.c is the module access the JTAG port of the device(s).
*
* The optional module cable.c is for supporting Lattice's parallel
* port ispDOWNLOAD cable on DOS and Windows 95/98 O/S. It can be
* requested from Lattice's ispVMSupport.
*
***************************************************************/
/**************************************************************
*
* Revision History of ispvm_ui.c
*
* 3/6/07 ht Added functions vme_out_char(),vme_out_hex(),
* vme_out_string() to provide output resources.
* Consolidate all printf() calls into the added output
* functions.
*
* 09/11/07 NN Added Global variables initialization
* 09/24/07 NN Added a switch allowing users to do calibration.
* Calibration will help to determine the system clock frequency
* and the count value for one micro-second delay of the target
* specific hardware.
* Removed Delay Percent support
* 11/15/07 NN moved the checking of the File CRC to the end of processing
* 08/28/08 NN Added Calculate checksum support.
***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <debug.h>
#include <vmopcode.h>
#include <unistd.h>
#include <firmware_app.h>
/***************************************************************
*
* File pointer to the VME file.
*
***************************************************************/
FILE *g_pVMEFile = NULL;
/***************************************************************
*
* Functions declared in this ispvm_ui.c module
*
***************************************************************/
unsigned char GetByte(void);
void vme_out_char(unsigned char charOut);
void vme_out_hex(unsigned char hexOut);
void vme_out_string(char *stringOut);
void ispVMMemManager(signed char cTarget, unsigned short usSize);
void ispVMFreeMem(void);
void error_handler(short a_siRetCode, char *pszMessage);
signed char ispVM(const char *a_pszFilename);
/***************************************************************
*
* Global variables.
*
***************************************************************/
unsigned short g_usPreviousSize = 0;
unsigned short g_usExpectedCRC = 0;
/***************************************************************
*
* External variables and functions declared in ivm_core.c module.
*
***************************************************************/
extern signed char ispVMCode();
extern void ispVMCalculateCRC32(unsigned char a_ucData);
extern void ispVMStart();
extern void ispVMEnd();
extern unsigned short g_usCalculatedCRC;
extern unsigned short g_usDataType;
extern unsigned char *g_pucOutMaskData,
*g_pucInData,
*g_pucOutData,
*g_pucHIRData,
*g_pucTIRData,
*g_pucHDRData,
*g_pucTDRData,
*g_pucOutDMaskData,
*g_pucIntelBuffer;
extern unsigned char *g_pucHeapMemory;
extern unsigned short g_iHeapCounter;
extern unsigned short g_iHEAPSize;
extern unsigned short g_usIntelDataIndex;
extern unsigned short g_usIntelBufferSize;
extern LVDSPair *g_pLVDSList;
//08/28/08 NN Added Calculate checksum support.
extern unsigned long g_usChecksum;
extern unsigned int g_uiChecksumIndex;
/* Added reinit for call ispvme more than once */
extern void ivm_core_reinit();
/***************************************************************
*
* External variables and functions declared in hardware.c module.
*
***************************************************************/
extern void calibration(void);
extern unsigned short g_usCpu_Frequency;
extern int g_file_fd;
/***************************************************************
*
* Supported VME versions.
*
***************************************************************/
const char *const g_szSupportedVersions[] = { "__VME2.0", "__VME3.0", "____12.0", "____12.1", 0 };
/***************************************************************
*
* GetByte
*
* Returns a byte to the caller. The returned byte depends on the
* g_usDataType register. If the HEAP_IN bit is set, then the byte
* is returned from the HEAP. If the LHEAP_IN bit is set, then
* the byte is returned from the intelligent buffer. Otherwise,
* the byte is returned directly from the VME file.
*
***************************************************************/
char* strlwr(char *str)
{
char *orig = str;
// process the string
for (; *str != '\0'; str++)
*str = tolower(*str);
return orig;
}
unsigned char GetByte()
{
unsigned char ucData = 0;
if (g_usDataType & HEAP_IN) {
/***************************************************************
*
* Get data from repeat buffer.
*
***************************************************************/
if (g_iHeapCounter > g_iHEAPSize) {
/***************************************************************
*
* Data over-run.
*
***************************************************************/
return 0xFF;
}
ucData = g_pucHeapMemory[g_iHeapCounter++];
}
else if ( g_usDataType & LHEAP_IN ) {
/***************************************************************
*
* Get data from intel buffer.
*
***************************************************************/
if (g_usIntelDataIndex >= g_usIntelBufferSize) {
/***************************************************************
*
* Data over-run.
*
***************************************************************/
return 0xFF;
}
ucData = g_pucIntelBuffer[g_usIntelDataIndex++];
}
else {
/***************************************************************
*
* Get data from file.
*
***************************************************************/
ucData = (unsigned char)fgetc(g_pVMEFile);
if (feof(g_pVMEFile)) {
/***************************************************************
*
* Reached EOF.
*
***************************************************************/
return 0xFF;
}
/***************************************************************
*
* Calculate the 32-bit CRC if the expected CRC exist.
*
***************************************************************/
if( g_usExpectedCRC != 0)
{
ispVMCalculateCRC32(ucData);
}
}
return (ucData);
}
/***************************************************************
*
* vme_out_char
*
* Send a character out to the output resource if available.
* The monitor is the default output resource.
*
*
***************************************************************/
void vme_out_char(unsigned char charOut)
{
dbg_print(is_debug_on, "%c", charOut);
}
/***************************************************************
*
* vme_out_hex
*
* Send a character out as in hex format to the output resource
* if available. The monitor is the default output resource.
*
*
***************************************************************/
void vme_out_hex(unsigned char hexOut)
{
dbg_print(is_debug_on, "%.2X", hexOut);
}
/***************************************************************
*
* vme_out_string
*
* Send a text string out to the output resource if available.
* The monitor is the default output resource.
*
*
***************************************************************/
void vme_out_string(char *stringOut)
{
dbg_print(is_debug_on,"%s",stringOut);
}
/***************************************************************
*
* ispVMMemManager
*
* Allocate memory based on cTarget. The memory size is specified
* by usSize.
*
***************************************************************/
void ispVMMemManager(signed char cTarget, unsigned short usSize)
{
switch (cTarget) {
case XTDI:
case TDI:
if (g_pucInData != NULL) {
if (g_usPreviousSize == usSize) { /*memory exist*/
break;
}
else {
free(g_pucInData);
g_pucInData = NULL;
}
}
g_pucInData = (unsigned char *)malloc(usSize / 8 + 2);
g_usPreviousSize = usSize;
case XTDO:
case TDO:
if (g_pucOutData != NULL) {
if (g_usPreviousSize == usSize) { /*already exist*/
break;
}
else {
free(g_pucOutData);
g_pucOutData = NULL;
}
}
g_pucOutData = (unsigned char *)malloc(usSize / 8 + 2);
g_usPreviousSize = usSize;
break;
case MASK:
if (g_pucOutMaskData != NULL) {
if (g_usPreviousSize == usSize) { /*already allocated*/
break;
}
else {
free(g_pucOutMaskData);
g_pucOutMaskData = NULL;
}
}
g_pucOutMaskData = (unsigned char *)malloc(usSize / 8 + 2);
g_usPreviousSize = usSize;
break;
case HIR:
if (g_pucHIRData != NULL) {
free(g_pucHIRData);
g_pucHIRData = NULL;
}
g_pucHIRData = (unsigned char *)malloc(usSize / 8 + 2);
break;
case TIR:
if (g_pucTIRData != NULL) {
free(g_pucTIRData);
g_pucTIRData = NULL;
}
g_pucTIRData = (unsigned char *)malloc(usSize / 8 + 2);
break;
case HDR:
if (g_pucHDRData != NULL) {
free(g_pucHDRData);
g_pucHDRData = NULL;
}
g_pucHDRData = (unsigned char *)malloc(usSize / 8 + 2);
break;
case TDR:
if (g_pucTDRData != NULL) {
free(g_pucTDRData);
g_pucTDRData = NULL;
}
g_pucTDRData = (unsigned char *)malloc(usSize / 8 + 2);
break;
case HEAP:
if (g_pucHeapMemory != NULL) {
free(g_pucHeapMemory);
g_pucHeapMemory = NULL;
}
g_pucHeapMemory = (unsigned char *)malloc(usSize + 2);
break;
case DMASK:
if (g_pucOutDMaskData != NULL) {
if (g_usPreviousSize == usSize) { /*already allocated*/
break;
}
else {
free(g_pucOutDMaskData);
g_pucOutDMaskData = NULL;
}
}
g_pucOutDMaskData = (unsigned char *)malloc(usSize / 8 + 2);
g_usPreviousSize = usSize;
break;
case LHEAP:
if (g_pucIntelBuffer != NULL) {
free(g_pucIntelBuffer);
g_pucIntelBuffer = NULL;
}
g_pucIntelBuffer = (unsigned char *)malloc(usSize + 2);
break;
case LVDS:
if (g_pLVDSList != NULL) {
free(g_pLVDSList);
g_pLVDSList = NULL;
}
g_pLVDSList = (LVDSPair * )calloc(usSize, sizeof(LVDSPair));
break;
default:
return;
}
}
/***************************************************************
*
* ispVMFreeMem
*
* Free memory that were dynamically allocated.
*
***************************************************************/
void ispVMFreeMem()
{
if (g_pucHeapMemory != NULL) {
free(g_pucHeapMemory);
g_pucHeapMemory = NULL;
}
if (g_pucOutMaskData != NULL) {
free(g_pucOutMaskData);
g_pucOutMaskData = NULL;
}
if (g_pucInData != NULL) {
free(g_pucInData);
g_pucInData = NULL;
}
if (g_pucOutData != NULL) {
free(g_pucOutData);
g_pucOutData = NULL;
}
if (g_pucHIRData != NULL) {
free(g_pucHIRData);
g_pucHIRData = NULL;
}
if (g_pucTIRData != NULL) {
free(g_pucTIRData);
g_pucTIRData = NULL;
}
if (g_pucHDRData != NULL) {
free(g_pucHDRData);
g_pucHDRData = NULL;
}
if (g_pucTDRData != NULL) {
free(g_pucTDRData);
g_pucTDRData = NULL;
}
if (g_pucOutDMaskData != NULL) {
free(g_pucOutDMaskData);
g_pucOutDMaskData = NULL;
}
if (g_pucIntelBuffer != NULL) {
free(g_pucIntelBuffer);
g_pucIntelBuffer = NULL;
}
if (g_pLVDSList != NULL) {
free(g_pLVDSList);
g_pLVDSList = NULL;
}
}
/***************************************************************
*
* error_handler
*
* Reports the error message.
*
***************************************************************/
void error_handler(short a_siRetCode, char *pszMessage)
{
const char *pszErrorMessage[] = { "pass",
"verification fail",
"can't find the file",
"wrong file type",
"file error",
"option error",
"crc verification error" };
strcpy(pszMessage, pszErrorMessage[-a_siRetCode]);
}
/***************************************************************
*
* ispVM
*
* The entry point of the ispVM embedded. If the version and CRC
* are verified, then the VME will be processed.
*
***************************************************************/
signed char ispVM(const char *a_pszFilename)
{
char szFileVersion[9] = { 0 };
signed char cRetCode = 0;
signed char cIndex = 0;
signed char cVersionIndex = 0;
unsigned char ucReadByte = 0;
int ret;
/***************************************************************
*
* Global variables initialization.
*
* 09/11/07 NN Added
***************************************************************/
g_pucHeapMemory = NULL;
g_iHeapCounter = 0;
g_iHEAPSize = 0;
g_usIntelDataIndex = 0;
g_usIntelBufferSize = 0;
g_usPreviousSize = 0;
/***************************************************************
*
* Open a file pointer to the VME file.
*
***************************************************************/
if ((g_pVMEFile = fopen(a_pszFilename, "rb")) == NULL) {
return VME_FILE_READ_FAILURE;
}
/* Skip the contents of the file header */
ret=fseek(g_pVMEFile, header_offset, SEEK_SET);
if (ret < 0) {
vme_out_string("Failed to skip header.\n");
fclose(g_pVMEFile);
g_pVMEFile = NULL;
return VME_ARGUMENT_FAILURE;
}
g_usCalculatedCRC = 0;
g_usExpectedCRC = 0;
ucReadByte = GetByte();
switch (ucReadByte) {
case FILE_CRC:
/***************************************************************
*
* Read and store the expected CRC to do the comparison at the end.
* Only versions 3.0 and higher support CRC protection.
*
***************************************************************/
g_usExpectedCRC = (unsigned char)fgetc(g_pVMEFile);
g_usExpectedCRC <<= 8;
g_usExpectedCRC |= fgetc(g_pVMEFile);
/***************************************************************
*
* Read and store the version of the VME file.
*
***************************************************************/
for (cIndex = 0; cIndex < 8; cIndex++) {
szFileVersion[cIndex] = GetByte();
}
break;
default:
/***************************************************************
*
* Read and store the version of the VME file. Must be version 2.0.
*
***************************************************************/
szFileVersion[0] = (signed char)ucReadByte;
for (cIndex = 1; cIndex < 8; cIndex++) {
szFileVersion[cIndex] = GetByte();
}
break;
}
/***************************************************************
*
* Compare the VME file version against the supported version.
*
***************************************************************/
for (cVersionIndex = 0; g_szSupportedVersions[cVersionIndex] != 0; cVersionIndex++) {
for (cIndex = 0; cIndex < 8; cIndex++) {
if (szFileVersion[cIndex] != g_szSupportedVersions[cVersionIndex][cIndex]) {
cRetCode = VME_VERSION_FAILURE;
break;
}
cRetCode = 0;
}
if (cRetCode == 0) {
/***************************************************************
*
* Found matching version, break.
*
***************************************************************/
break;
}
}
if (cRetCode < 0) {
/***************************************************************
*
* VME file version failed to match the supported versions.
*
***************************************************************/
fclose(g_pVMEFile);
g_pVMEFile = NULL;
return VME_VERSION_FAILURE;
}
/***************************************************************
*
* Enable the JTAG port to communicate with the device.
* Set the JTAG state machine to the Test-Logic/Reset State.
*
***************************************************************/
ispVMStart();
/***************************************************************
*
* Process the VME file.
*
***************************************************************/
cRetCode = ispVMCode();
/***************************************************************
*
* Set the JTAG State Machine to Test-Logic/Reset state then disable
* the communication with the JTAG port.
*
***************************************************************/
ispVMEnd();
fclose(g_pVMEFile);
g_pVMEFile = NULL;
ispVMFreeMem();
/***************************************************************
*
* Compare the expected CRC versus the calculated CRC.
*
***************************************************************/
if (cRetCode == 0 && g_usExpectedCRC != 0 && (g_usExpectedCRC != g_usCalculatedCRC)) {
printf("Expected CRC: 0x%.4X\n", g_usExpectedCRC);
printf("Calculated CRC: 0x%.4X\n", g_usCalculatedCRC);
return VME_CRC_FAILURE;
}
return (cRetCode);
}
/***************************************************************
*
* ispvme_reinit
*
* Reinit ispvm_ui variables.
*
***************************************************************/
static void ispvm_ui_reinit()
{
g_pVMEFile = NULL;
g_usPreviousSize = 0;
g_usExpectedCRC = 0;
}
/***************************************************************
*
* main
*
***************************************************************/
int ispvme_main(int argc, char *argv[], int file_fd, name_info_t *info)
{
unsigned short iCommandLineIndex = 0;
short siRetCode = 0;
char szExtension[5] = { 0 };
char szCommandLineArg[300] = { 0 };
short sicalibrate = 0;
ispvm_ui_reinit();
ivm_core_reinit();
//08/28/08 NN Added Calculate checksum support.
g_usChecksum = 0;
g_uiChecksumIndex = 0;
if (file_fd < 0) {
dbg_print(is_debug_on, "Error:firmware upgrade ispvme dev parameters failed.\r\n");
return -1;
} else {
g_file_fd = file_fd;
}
#if 0
ret = firmware_check_chip_name(g_file_fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip name: %s.\n", file_name);
close(g_file_fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
ret = firmware_check_chip_verison(g_file_fd, info);
if (ret != FIRMWARE_SUCCESS) {
dbg_print(is_debug_on, "Error: Failed to check chip version: %s.\n", file_name);
close(g_file_fd);
return firmware_error_type(FIRMWARE_ACTION_CHECK, info);
}
#endif
vme_out_string(" Lattice Semiconductor Corp.\n");
vme_out_string("\n ispVME(tm) V");
vme_out_string(VME_VERSION_NUMBER);
vme_out_string(" Copyright 1998-2011.\n");
vme_out_string("\nFor daisy chain programming of all in-system programmable devices\n\n");
if (argc < 2) {
vme_out_string("\nUsage: vme [option] vme_file [vme_file]\n");
vme_out_string("Example: vme vme_file1.vme vme_file2.vme\n");
vme_out_string("option -c: do the calibration.\n");
vme_out_string("Example: vme -c\n");
vme_out_string("Example: vme -c vme_file1.vme vme_file2.vme\n");
vme_out_string("\n\n");
g_file_fd = -1;
/* Change return to determine whether the upgrade was successful */
return -1;
}
for (iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++) {
strncpy(szCommandLineArg, argv[iCommandLineIndex], sizeof(szCommandLineArg) - 1);
if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex == 1)) {
sicalibrate = 1;
} else if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex != 1)) {
vme_out_string("Error: calibrate option -c must be the first argument\n\n");
g_file_fd = -1;
/* Change return to determine whether the upgrade was successful */
return -1;
//exit(1);
} else {
strcpy(szExtension, &szCommandLineArg[strlen(szCommandLineArg) - 4]);
strlwr(szExtension);
if (strcmp(szExtension, ".vme")) {
vme_out_string("Error: VME files must end with the extension *.vme\n\n");
g_file_fd = -1;
/* Change return to determine whether the upgrade was successful */
return -1;
//exit(1);
}
}
}
siRetCode = 0;
if (sicalibrate) {
calibration();
}
for (iCommandLineIndex = 1; iCommandLineIndex < argc; iCommandLineIndex++) { /* Process all VME files sequentially */
strcpy(szCommandLineArg, argv[iCommandLineIndex]);
if (!strcmp(strlwr(szCommandLineArg), "-c") && (iCommandLineIndex == 1)) {
} else if (!strcmp(strlwr(szCommandLineArg), "-checksum")) {
} else {
vme_out_string("Processing virtual machine file (");
vme_out_string(szCommandLineArg);
vme_out_string(")......\n\n");
siRetCode = ispVM(argv[iCommandLineIndex]);
if (siRetCode < 0) {
break;
}
}
}
if (siRetCode < 0) {
error_handler(siRetCode, szCommandLineArg);
vme_out_string("Failed due to ");
vme_out_string(szCommandLineArg);
vme_out_string("\n\n");
vme_out_string("+=======+\n");
vme_out_string("| FAIL! |\n");
vme_out_string("+=======+\n\n");
} else {
vme_out_string("+=======+\n");
vme_out_string("| PASS! |\n");
vme_out_string("+=======+\n\n");
//08/28/08 NN Added Calculate checksum support.
if (g_usChecksum != 0) {
g_usChecksum &= 0xFFFF;
printf("Data Checksum: %.4X\n\n", (unsigned int)g_usChecksum);
g_usChecksum = 0;
}
}
g_file_fd = -1;
/* Change return to determine whether the upgrade was successful */
return siRetCode;
//exit(siRetCode);
}
/*
* firmware_upgrade_ispvme
* function: ispvme firmware upgrade
* @file_fd: param[in] Upgrade devices fd
* @upgrade_file_name: param[in] Upgrade file name
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS, other fail return error code
*/
int firmware_upgrade_ispvme(int file_fd, char *upgrade_file_name, name_info_t *info)
{
char *argv[2];
int ret, rv, i, retry;
argv[1] = upgrade_file_name;
/* Initialize and enable */
rv = ioctl(file_fd, FIRMWARE_JTAG_INIT,NULL);
if (rv < 0) {
vme_out_string("Failed to init GPIO.\n");
return VME_ARGUMENT_FAILURE;
}
i = 0;
retry = FIRMWARE_UPGRADE_RETRY_CNT;
ret = 0;
while(i < retry) {
ret = ispvme_main(2, argv, file_fd, info);
if (ret < 0) {
i++;
dbg_print(is_debug_on, "%d times ispvme upgrade failed. ret %d.\n", i, ret);
continue;
} else {
dbg_print(is_debug_on, "ispvme upgrade success.\n");
break;
}
}
/* Upgrade completed, release */
rv = ioctl(file_fd, FIRMWARE_JTAG_FINISH, NULL);
if (rv < 0) {
vme_out_string("Failed to release GPIO.\n");
return VME_ARGUMENT_FAILURE;
}
return ret;
}

View File

@ -0,0 +1,68 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <linux/version.h>
#include <stdlib.h>
#include <unistd.h>
#include <firmware_app.h>
/*
* firmware_upgrade_jtag
* function: Determine whether to upgrade ISC or JBI
* @fd: param[in] Device file descriptor
* @buf: param[in] Upgrade the file content
* @size: param[in] Upgrade file size
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_upgrade_jtag(int fd, uint8_t *buf, uint32_t size, name_info_t *info)
{
int ret;
cmd_info_t cmd_info;
cmd_info.size = size;
cmd_info.data = buf;
ret = 0;
if (info->type == FIRMWARE_CPLD) {
/* 0x4A,0x41,0x4D,0x01 is JBI file */
if (buf[0] == 0x4A && buf[1] == 0x41 && buf[2] == 0x4D && buf[3] == 0x01) {
dbg_print(is_debug_on, "Use jbi file.\n");
ret = ioctl(fd, FIRMWARE_PROGRAM_JBI, &cmd_info);
} else {
dbg_print(is_debug_on, "Use isc file.\n");
ret = ioctl(fd, FIRMWARE_PROGRAM, &cmd_info);
}
}
if (info->type == FIRMWARE_FPGA) {
ret = ioctl(fd, FIRMWARE_PROGRAM, &cmd_info);
}
if (ret < 0) {
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_jtag_test
* function: Determine whether to upgrade ISC or JBI
* @fd: param[in] Device file descriptor
* @buf: param[in] Upgrade the file content
* @size: param[in] Upgrade file size
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_upgrade_jtag_test(int fd, uint8_t *buf, uint32_t size, name_info_t *info)
{
return FIRMWARE_SUCCESS;
}

View File

@ -0,0 +1,446 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <linux/version.h>
#include <stdlib.h>
#include <unistd.h>
#include <firmware_app.h>
#include "firmware_upgrade_mtd.h"
#include "mtd-abi.h"
static int get_mtdnum_from_name(char *name, int *mtdnum)
{
FILE *fp;
int ret;
char buf[PATH_LEN];
char *start;
char *end;
char *key_w = "mtd";
if (name == NULL || mtdnum == NULL) {
dbg_print(is_debug_on, "Input invalid error.\n");
return -EINVAL;
}
ret = 0;
*mtdnum = -1;
fp = fopen("/proc/mtd", "r");
if (fp == NULL) {
dbg_print(is_debug_on, "Not find mtd device.\n");
return -FIRWMARE_MTD_PART_INFO_ERR;
}
mem_clear(buf, sizeof(buf));
while(fgets(buf, sizeof(buf), fp)) {
if (strstr(buf, name) != NULL) {
start = strstr(buf, key_w);
if (start == NULL) {
dbg_print(is_debug_on, "/proc/mtd don't find %s.\n", key_w);
ret = -FIRWMARE_MTD_PART_INFO_ERR;
goto exit;
}
start += strlen(key_w);
end = strchr(start, ':');
if (end == NULL) {
dbg_print(is_debug_on, "/proc/mtd don't find %c.\n", ':');
ret = -FIRWMARE_MTD_PART_INFO_ERR;
goto exit;
}
*end = '\0';
*mtdnum = atoi(start);
if (*mtdnum < 0) {
dbg_print(is_debug_on, "Not get mtd num.\n");
ret = -FIRWMARE_MTD_PART_INFO_ERR;
goto exit;
}
}
}
if (*mtdnum == -1) {
ret = -FIRWMARE_MTD_PART_INFO_ERR;
goto exit;
}
exit:
if (fp != NULL) {
fclose(fp);
}
return ret;
}
static int firmware_sysfs_get_dev_info(int fd, firmware_mtd_info_t *dev_info)
{
int ret;
ret = ioctl(fd, FIRMWARE_SYSFS_MTD_INFO, dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "Failed to get upg device file info.\n");
return ret;
}
dbg_print(is_debug_on, "mtd_name=%s flash_base=0x%x test_base=0x%x test_size=%d.\n",
dev_info->mtd_name, dev_info->flash_base, dev_info->test_base, dev_info->test_size);
return 0;
}
/*
* MEMGETINFO
*/
static int getmeminfo(int fd, struct mtd_info_user *mtd)
{
return ioctl(fd, MEMGETINFO, mtd);
}
/*
* MEMERASE
*/
static int memerase(int fd, struct erase_info_user *erase)
{
return ioctl(fd, MEMERASE, erase);
}
static int erase_flash(int fd, uint32_t offset, uint32_t bytes)
{
int err;
struct erase_info_user erase;
erase.start = offset;
erase.length = bytes;
err = memerase(fd, &erase);
if (err < 0) {
dbg_print(is_debug_on, "Error: memerase failed, err=%d\n", err);
return -FIRWMARE_MTD_MEMERASE;
}
dbg_print(is_debug_on, "Erased %d bytes from address 0x%.8x in flash\n", bytes, offset);
return 0;
}
/*
* firmware_upgrade_mtd_block
* function: upgrade mtd device block
* @dev_info: param[in] Device file descriptor
* @buf: param[in] Upgrade the file content
* @size: param[in] Upgrade file size
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int firmware_upgrade_mtd_block(int mtd_fd, uint32_t offset,
uint8_t *buf, uint32_t size, uint32_t erasesize)
{
int ret;
int i;
uint8_t *reread_buf;
uint32_t cmp_retry, reread_len, write_len;
/* Read back data */
reread_buf = (uint8_t *) malloc(size);
if (reread_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for read back data buf, size=%d.\n", size);
return FIRMWARE_FAILED;
}
for (cmp_retry = 0; cmp_retry < FW_SYSFS_RETRY_TIME; cmp_retry++) {
for (i = 0; i < FW_SYSFS_RETRY_TIME; i++) {
if (offset != lseek(mtd_fd, offset, SEEK_SET)) {
dbg_print(is_debug_on, "Error:lseek mtd offset=%x retrytimes=%d failed.\n", offset, i);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
dbg_print(is_debug_on, "erase mtd offset=0x%x erasesize=%d retrytimes=%d.\n",
offset, erasesize, i);
ret = erase_flash(mtd_fd, offset, erasesize);
if (ret < 0) {
dbg_print(is_debug_on, "Error:erase mtd offset=%x size=%d retrytimes=%d failed, ret=%d\n",
offset, size, i, ret);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
dbg_print(is_debug_on, "write mtd offset=0x%x size=%d retrytimes=%d.\n",
offset, size, i);
write_len = write(mtd_fd, buf, size);
if (write_len != size) {
dbg_print(is_debug_on, "Error:write mtd offset=0x%x size=%d write_len=%d retrytimes=%d.\n",
offset, size, write_len, i);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
break;
}
if (i == FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "Error: upgrade mtd fail, offset = 0x%x, size = %d\n", offset, size);
free(reread_buf);
return FIRMWARE_FAILED;
}
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
dbg_print(is_debug_on, "Reread mtd offset=0x%x size=%d\n", offset, size);
for (i = 0; i < FW_SYSFS_RETRY_TIME; i++) {
if (offset != lseek(mtd_fd, offset, SEEK_SET)) {
dbg_print(is_debug_on, "Error:lseek mtd offset=%x retrytimes=%d failed.\n", offset, i);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
reread_len = read(mtd_fd, reread_buf, size);
if (reread_len != size) {
dbg_print(is_debug_on, "Error:reread mtd offset=0x%x size=%d reread_len=%d retrytimes=%d.\n",
offset, size, reread_len, i);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
break;
}
if (i == FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "Error: reread mtd fail, offset = 0x%x size = %d\n", offset, size);
free(reread_buf);
return FIRMWARE_FAILED;
}
/* Check data */
if (memcmp(reread_buf, buf, size) != 0) {
dbg_print(is_debug_on, "memcmp mtd fail,offset = 0x%x retrytimes = %d\n", offset, cmp_retry);
} else {
break;
}
}
if (cmp_retry >= FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "upgrade mtd fail, offset = 0x%x.\n", offset);
dbg_print(is_debug_on, "want to write buf :\n");
for (i = 0; i < size; i++) {
dbg_print(is_debug_on, "0x%x ", buf[i]);
if (((i + 1) % 16) == 0) {
dbg_print(is_debug_on, "\n");
}
}
dbg_print(is_debug_on, "\n");
dbg_print(is_debug_on, "actually reread buf :\n");
for (i = 0; i < size; i++) {
dbg_print(is_debug_on, "0x%x ", reread_buf[i]);
if (((i + 1) % 16) == 0) {
dbg_print(is_debug_on, "\n");
}
}
dbg_print(is_debug_on, "\n");
free(reread_buf);
return FIRMWARE_FAILED;
}
free(reread_buf);
dbg_print(is_debug_on, "firmware upgrade mtd block offset[0x%.8x] success.\n", offset);
return FIRMWARE_SUCCESS;
}
/*
* firmware_upgrade_mtd_program
* function: upgrade mtd device
* @dev_info: param[in] Device file descriptor
* @flash_base: param[in] Upgrade the flash start address
* @buf: param[in] Upgrade the file content
* @size: param[in] Upgrade file size
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
static int firmware_upgrade_mtd_program(firmware_mtd_info_t *dev_info,
int flash_base, uint8_t *buf, uint32_t size)
{
int ret;
int mtdnum;
char dev_mtd[PATH_LEN];
int mtd_fd;
uint32_t offset, len, block_size;
struct mtd_info_user mtd_info;
uint8_t *data_point;
ret = get_mtdnum_from_name(dev_info->mtd_name, &mtdnum);
if (ret < 0) {
dbg_print(is_debug_on, "Error:not find %s mtd num.\n", dev_info->mtd_name);
return FIRMWARE_FAILED;
}
mem_clear(dev_mtd, sizeof(dev_mtd));
snprintf(dev_mtd, sizeof(dev_mtd) - 1, "/dev/mtd%d", mtdnum);
mtd_fd = open(dev_mtd, O_SYNC | O_RDWR);
if (mtd_fd < 0) {
dbg_print(is_debug_on, "Error:open %s failed.\n", dev_mtd);
goto err;
}
ret = getmeminfo(mtd_fd, &mtd_info);
if (ret < 0) {
dbg_print(is_debug_on, "Error:get mtd info failed, ret=%d.\n", ret);
goto failed;
}
offset = flash_base;
if (offset >= mtd_info.size) {
dbg_print(is_debug_on, "Error: offset[0x%.8x] over size[0x%.8x]\n", offset, size);
goto failed;
}
len = size;
data_point = buf;
while ((offset < mtd_info.size) && (len > 0)) {
if (len > mtd_info.erasesize) {
block_size = mtd_info.erasesize;
} else {
block_size = len;
}
dbg_print(is_debug_on, "upgrade mtd[%s] block offset[0x%.8x] size[%d] relen[%d].\n", dev_mtd, offset, size, len);
ret = firmware_upgrade_mtd_block(mtd_fd, offset, data_point, block_size, mtd_info.erasesize);
if (ret < 0) {
dbg_print(is_debug_on, "Error: mt block offset[0x%.8x] size[0x%.8x] failed.\n", offset, block_size);
goto failed;
}
len -= block_size;
data_point += block_size;
offset += block_size;
usleep(FW_MTD_BLOCK_SLEEP_TIME);
}
if (close(mtd_fd) < 0) {
dbg_print(is_debug_on, "Error:close %s failed.\n", dev_mtd);
}
dbg_print(is_debug_on, "firmware upgrade mtd device success.\n");
return FIRMWARE_SUCCESS;
failed:
if (close(mtd_fd) < 0) {
dbg_print(is_debug_on, "Error:close %s failed.\n", dev_mtd);
}
err:
dbg_print(is_debug_on, "firmware upgrade mtd device fail.\n");
return FIRMWARE_FAILED;
}
/*
* firmware_upgrade_mtd
* function: Determine whether to upgrade ISC or JBI
* @fd: param[in] Device file descriptor
* @buf: param[in] Upgrade the file content
* @size: param[in] Upgrade file size
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_upgrade_mtd(int fd, uint8_t *buf, uint32_t size, name_info_t *info)
{
int ret;
firmware_mtd_info_t dev_info;
if ((buf == NULL) || (info == NULL)) {
dbg_print(is_debug_on, "Input invalid error.\n");
return FIRMWARE_FAILED;
}
/* get sysfs information*/
ret = firmware_sysfs_get_dev_info(fd, &dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "firmware_sysfs_get_dev_info failed, ret %d.\n", ret);
return FIRMWARE_FAILED;
}
/* enable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_INIT, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
return FIRMWARE_FAILED;
}
ret = firmware_upgrade_mtd_program(&dev_info, dev_info.flash_base, buf, size);
if (ret < 0) {
dbg_print(is_debug_on, "Error:mtd device program failed, ret=%d.\n", ret);
goto failed;
}
/* disable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_FINISH, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
return FIRMWARE_SUCCESS;
failed:
/* disable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_FINISH,NULL);
if (ret < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
return FIRMWARE_FAILED;
}
/*
* firmware_upgrade_mtd_test
* function: Determine whether to upgrade ISC or JBI
* @fd: param[in] Device file descriptor
* @info: param[in] Upgrade file information
* return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
*/
int firmware_upgrade_mtd_test(int fd, name_info_t *info)
{
int ret, rv;
firmware_mtd_info_t dev_info;
uint8_t *data_buf;
uint8_t num;
int j;
if (info == NULL) {
dbg_print(is_debug_on, "Input invalid error.\n");
return FIRMWARE_FAILED;
}
/* get sysfs information*/
ret = firmware_sysfs_get_dev_info(fd, &dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "firmware_sysfs_get_dev_info failed, ret %d.\n", ret);
return FIRMWARE_FAILED;
}
if (dev_info.test_size == 0) {
dbg_print(is_debug_on, "Error: get flash size:%d, not support.\n", dev_info.test_size);
return FIRMWARE_NOT_SUPPORT;
}
data_buf = (uint8_t *) malloc(dev_info.test_size);
if (data_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for test data buf, size=%d.\n", dev_info.test_size);
return FIRMWARE_FAILED;
}
/* Get random data */
for (j = 0; j < dev_info.test_size; j++) {
num = (uint8_t) rand() % 256;
data_buf[j] = num & 0xff;
}
/* enable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_INIT, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
free(data_buf);
return FIRMWARE_FAILED;
}
ret = firmware_upgrade_mtd_program(&dev_info, dev_info.test_base, data_buf, dev_info.test_size);
/* disable upgrade access */
rv = ioctl(fd, FIRMWARE_SYSFS_FINISH, NULL);
if (rv < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
free(data_buf);
if (ret < 0) {
dbg_print(is_debug_on, "Error:mtd device program failed, ret=%d.\n", ret);
return FIRMWARE_FAILED;
}
return FIRMWARE_SUCCESS;
}

View File

@ -0,0 +1,32 @@
#ifndef __FIRMWARE_UPGRADE_MTD_H__
#define __FIRMWARE_UPGRADE_MTD_H__
#include <firmware_app.h>
#define FIRMWARE_DEV_NAME_LEN 64 /* the macro definition needs to same as FIRMWARE_DEV_NAME_LEN in firmware_sysfs_upgrade.h */
#define PATH_LEN (256)
#define FW_MTD_BLOCK_SLEEP_TIME (10000) /* 10ms */
#define FW_SYSFS_RETRY_SLEEP_TIME (10000) /* 10ms */
#define FW_SYSFS_RETRY_TIME (5) /* retry 5 times, 50ms = FW_SYSFS_RETRY_TIME *FW_SYSFS_RETRY_SLEEP_TIME; */
/* Debug switch level */
typedef enum {
FIRWMARE_MTD_SUCCESS = 0,
FIRWMARE_MTD_PART_INFO_ERR,
FIRWMARE_MTD_MEMERASE,
FIRWMARE_MTD_MEMGETINFO,
FIRWMARE_END,
} firmware_debug_level_t;
#define debug(fmt, argv...) do { \
dbg_print(is_debug_on, ""fmt , ##argv);\
} while(0)
typedef struct firmware_mtd_info_s {
char mtd_name[FIRMWARE_DEV_NAME_LEN]; /* sysfs name */
uint32_t flash_base; /* Flash Upgrade Address */
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
} firmware_mtd_info_t;
#endif /* End of __FIRMWARE_UPGRADE_MTD_H__ */

View File

@ -0,0 +1,259 @@
#ifndef __MTD_ABI_H__
#define __MTD_ABI_H__
#include <linux/types.h>
struct erase_info_user {
__u32 start;
__u32 length;
};
struct erase_info_user64 {
__u64 start;
__u64 length;
};
struct mtd_oob_buf {
__u32 start;
__u32 length;
unsigned char *ptr;
};
struct mtd_oob_buf64 {
__u64 start;
__u32 pad;
__u32 length;
__u64 usr_ptr;
};
/**
* MTD operation modes
*
* @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default)
* @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas
* which are defined by the internal ecclayout
* @MTD_OPS_RAW: data are transferred as-is, with no error correction;
* this mode implies %MTD_OPS_PLACE_OOB
*
* These modes can be passed to ioctl(MEMWRITE) and are also used internally.
* See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
* %MTD_FILE_MODE_RAW.
*/
enum {
MTD_OPS_PLACE_OOB = 0,
MTD_OPS_AUTO_OOB = 1,
MTD_OPS_RAW = 2,
};
/**
* struct mtd_write_req - data structure for requesting a write operation
*
* @start: start address
* @len: length of data buffer
* @ooblen: length of OOB buffer
* @usr_data: user-provided data buffer
* @usr_oob: user-provided OOB buffer
* @mode: MTD mode (see "MTD operation modes")
* @padding: reserved, must be set to 0
*
* This structure supports ioctl(MEMWRITE) operations, allowing data and/or OOB
* writes in various modes. To write to OOB-only, set @usr_data == NULL, and to
* write data-only, set @usr_oob == NULL. However, setting both @usr_data and
* @usr_oob to NULL is not allowed.
*/
struct mtd_write_req {
__u64 start;
__u64 len;
__u64 ooblen;
__u64 usr_data;
__u64 usr_oob;
__u8 mode;
__u8 padding[7];
};
#define MTD_ABSENT 0
#define MTD_RAM 1
#define MTD_ROM 2
#define MTD_NORFLASH 3
#define MTD_NANDFLASH 4
#define MTD_DATAFLASH 6
#define MTD_UBIVOLUME 7
#define MTD_MLCNANDFLASH 8
#define MTD_WRITEABLE 0x400 /* Device is writeable */
#define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */
#define MTD_NO_ERASE 0x1000 /* No erase necessary */
#define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */
/* Some common devices / combinations of capabilities */
#define MTD_CAP_ROM 0
#define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
#define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE)
#define MTD_CAP_NANDFLASH (MTD_WRITEABLE)
/* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */
#define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended)
#define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode)
#define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme
#define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read)
#define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default
/* OTP mode selection */
#define MTD_OTP_OFF 0
#define MTD_OTP_FACTORY 1
#define MTD_OTP_USER 2
typedef struct mtd_info_user {
__u8 type;
__u32 flags;
__u32 size; /* Total size of the MTD */
__u32 erasesize;
__u32 writesize;
__u32 oobsize; /* Amount of OOB data per block (e.g. 16) */
__u64 padding; /* Old obsolete field; do not use */
} mtd_info_user_t;
struct region_info_user {
__u32 offset; /* At which this region starts,
* from the beginning of the MTD */
__u32 erasesize; /* For this region */
__u32 numblocks; /* Number of blocks in this region */
__u32 regionindex;
};
struct otp_info {
__u32 start;
__u32 length;
__u32 locked;
};
/*
* Note, the following ioctl existed in the past and was removed:
* #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo)
* Try to avoid adding a new ioctl with the same ioctl number.
*/
/* Get basic MTD characteristics info (better to use sysfs) */
#define MEMGETINFO _IOR('M', 1, struct mtd_info_user)
/* Erase segment of MTD */
#define MEMERASE _IOW('M', 2, struct erase_info_user)
/* Write out-of-band data from MTD */
#define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf)
/* Read out-of-band data from MTD */
#define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf)
/* Lock a chip (for MTD that supports it) */
#define MEMLOCK _IOW('M', 5, struct erase_info_user)
/* Unlock a chip (for MTD that supports it) */
#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)
/* Get the number of different erase regions */
#define MEMGETREGIONCOUNT _IOR('M', 7, int)
/* Get information about the erase region for a specific index */
#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user)
/* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
#define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo)
/* Check if an eraseblock is bad */
#define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t)
/* Mark an eraseblock as bad */
#define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t)
/* Set OTP (One-Time Programmable) mode (factory vs. user) */
#define OTPSELECT _IOR('M', 13, int)
/* Get number of OTP (One-Time Programmable) regions */
#define OTPGETREGIONCOUNT _IOW('M', 14, int)
/* Get all OTP (One-Time Programmable) info about MTD */
#define OTPGETREGIONINFO _IOW('M', 15, struct otp_info)
/* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
#define OTPLOCK _IOR('M', 16, struct otp_info)
/* Get ECC layout (deprecated) */
#define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user)
/* Get statistics about corrected/uncorrected errors */
#define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats)
/* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
#define MTDFILEMODE _IO('M', 19)
/* Erase segment of MTD (supports 64-bit address) */
#define MEMERASE64 _IOW('M', 20, struct erase_info_user64)
/* Write data to OOB (64-bit version) */
#define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64)
/* Read data from OOB (64-bit version) */
#define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64)
/* Check if chip is locked (for MTD that supports it) */
#define MEMISLOCKED _IOR('M', 23, struct erase_info_user)
/*
* Most generic write interface; can write in-band and/or out-of-band in various
* modes (see "struct mtd_write_req")
*/
#define MEMWRITE _IOWR('M', 24, struct mtd_write_req)
/*
* Obsolete legacy interface. Keep it in order not to break userspace
* interfaces
*/
struct nand_oobinfo {
__u32 useecc;
__u32 eccbytes;
__u32 oobfree[8][2];
__u32 eccpos[32];
};
struct nand_oobfree {
__u32 offset;
__u32 length;
};
#define MTD_MAX_OOBFREE_ENTRIES 8
#define MTD_MAX_ECCPOS_ENTRIES 64
/*
* OBSOLETE: ECC layout control structure. Exported to user-space via ioctl
* ECCGETLAYOUT for backwards compatbility and should not be mistaken as a
* complete set of ECC information. The ioctl truncates the larger internal
* structure to retain binary compatibility with the static declaration of the
* ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of
* the user struct, not the MAX size of the internal struct nand_ecclayout.
*/
struct nand_ecclayout_user {
__u32 eccbytes;
__u32 eccpos[MTD_MAX_ECCPOS_ENTRIES];
__u32 oobavail;
struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
};
/**
* struct mtd_ecc_stats - error correction stats
*
* @corrected: number of corrected bits
* @failed: number of uncorrectable errors
* @badblocks: number of bad blocks in this partition
* @bbtblocks: number of blocks reserved for bad block tables
*/
struct mtd_ecc_stats {
__u32 corrected;
__u32 failed;
__u32 badblocks;
__u32 bbtblocks;
};
/*
* MTD file modes - for read/write access to MTD
*
* @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled
* @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode
* @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode
* @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled
*
* These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained
* separately for each open file descriptor.
*
* Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
* raw access to the flash, without error correction or autoplacement schemes.
* Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
* (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
* used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
*/
enum mtd_file_modes {
MTD_FILE_MODE_NORMAL = MTD_OTP_OFF,
MTD_FILE_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
MTD_FILE_MODE_OTP_USER = MTD_OTP_USER,
MTD_FILE_MODE_RAW,
};
#endif /* __MTD_ABI_H__ */

View File

@ -0,0 +1,285 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <linux/version.h>
#include <stdlib.h>
#include <unistd.h>
#include <firmware_app.h>
#include "firmware_upgrade_sysfs.h"
static int firmware_sysfs_get_dev_info(int fd, firmware_dev_file_info_t *dev_info)
{
int ret;
ret = ioctl(fd, FIRMWARE_SYSFS_DEV_FILE_INFO, dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "Failed to get upg flash dev info.\n");
return ret;
}
dbg_print(is_debug_on, "sysfs_name=%s per_len=%u.\n", dev_info->sysfs_name, dev_info->per_len);
return 0;
}
/* sysfs upgrade program function */
int firmware_upgrade_sysfs_program(firmware_dev_file_info_t *dev_info, uint32_t dev_base,
uint8_t *buf, uint32_t size)
{
int ret = 0;
uint32_t offset_addr, buf_offset, len;
uint32_t write_len, cmp_retry, reread_len;
int sysfs_fd;
uint8_t *reread_buf;
int i;
if (dev_info->per_len > 0) {
if (size % dev_info->per_len) {
dbg_print(is_debug_on, "firmware sysfs upgrade size[%u] is width[%u] mismatch, ret %d.\n",
size, dev_info->per_len, ret);
return FIRMWARE_FAILED;
}
len = dev_info->per_len;
} else {
/* Write to the maximum buffer if the length of each write is not configured */
len = size;
}
/* Read back data */
reread_buf = (uint8_t *) malloc(len);
if (reread_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for read back data buf, len=%u.\n", len);
return FIRMWARE_FAILED;
}
sysfs_fd = open(dev_info->sysfs_name, O_RDWR | O_SYNC);
if (sysfs_fd < 0) {
dbg_print(is_debug_on, "open file[%s] fail.\n", dev_info->sysfs_name);
free(reread_buf);
return FIRMWARE_FAILED;
}
offset_addr = dev_base;
buf_offset = 0;
cmp_retry = 0;
while (buf_offset < size) {
/* Calibrate upgrade data length */
if (buf_offset + len > size) {
len = size - buf_offset;
}
for (i = 0; i < FW_SYSFS_RETRY_TIME; i++) {
ret = lseek(sysfs_fd, offset_addr, SEEK_SET);
if (ret < 0) {
dbg_print(is_debug_on, "lseek file[%s offset=%u] fail.\n", dev_info->sysfs_name, offset_addr);
close(sysfs_fd);
free(reread_buf);
return FIRMWARE_FAILED;
}
write_len = write(sysfs_fd, buf + buf_offset, len);
if (write_len != len) {
dbg_print(is_debug_on, "write file[%s] fail,offset = 0x%x retrytimes = %u len = %u, write_len =%u\n",
dev_info->sysfs_name, offset_addr, i ,len, write_len);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
break;
}
if (i == FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "write file[%s] fail, offset = 0x%x, len = %u, write_len =%u\n",
dev_info->sysfs_name, offset_addr, len, write_len);
close(sysfs_fd);
free(reread_buf);
return FIRMWARE_FAILED;
}
mem_clear(reread_buf, len);
ret = lseek(sysfs_fd, offset_addr, SEEK_SET);
if (ret < 0) {
dbg_print(is_debug_on, "reread lseek file[%s offset=%u] fail.\n", dev_info->sysfs_name, offset_addr);
close(sysfs_fd);
free(reread_buf);
return FIRMWARE_FAILED;
}
for (i = 0; i < FW_SYSFS_RETRY_TIME; i++) {
reread_len = read(sysfs_fd, reread_buf, len);
if (reread_len != len) {
dbg_print(is_debug_on, "reread file[%s] fail,offset = 0x%x retrytimes = %u reread_len = %u, len =%u\n",
dev_info->sysfs_name, offset_addr, i ,reread_len, len);
usleep(FW_SYSFS_RETRY_SLEEP_TIME);
continue;
}
break;
}
if (i == FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "reread file[%s] fail, offset = 0x%x, reread_len = %u, len = %u\n",
dev_info->sysfs_name, offset_addr, reread_len, len);
close(sysfs_fd);
free(reread_buf);
return FIRMWARE_FAILED;
}
/* Check data */
if (memcmp(reread_buf, buf + buf_offset, len) != 0) {
if (cmp_retry < FW_SYSFS_RETRY_TIME) {
dbg_print(is_debug_on, "memcmp file[%s] fail,offset = 0x%x retrytimes = %u\n",
dev_info->sysfs_name, offset_addr, cmp_retry);
cmp_retry++;
continue;
}
dbg_print(is_debug_on, "upgrade file[%s] fail, offset = 0x%x.\n", dev_info->sysfs_name, offset_addr);
dbg_print(is_debug_on, "want to write buf :\n");
for (i = 0; i < len; i++) {
dbg_print(is_debug_on, "0x%x ", buf[buf_offset + i]);
if (((i + 1) % 16) == 0) {
dbg_print(is_debug_on, "\n");
}
}
dbg_print(is_debug_on, "\n");
dbg_print(is_debug_on, "actually reread buf :\n");
for (i = 0; i < len; i++) {
dbg_print(is_debug_on, "0x%x ", reread_buf[i]);
if (((i + 1) % 16) == 0) {
dbg_print(is_debug_on, "\n");
}
}
dbg_print(is_debug_on, "\n");
close(sysfs_fd);
free(reread_buf);
return FIRMWARE_FAILED;
}
offset_addr += len;
buf_offset += len;
usleep(5000);
}
free(reread_buf);
dbg_print(is_debug_on, "firmware upgrade sysfs success.\n");
close(sysfs_fd);
return FIRMWARE_SUCCESS;
}
/* sysfs upgrade function */
int firmware_upgrade_sysfs(int fd, uint8_t *buf, uint32_t size, name_info_t *info)
{
int ret = 0;
firmware_dev_file_info_t dev_info;
if ((buf == NULL) || (info == NULL)) {
dbg_print(is_debug_on, "Input invalid error.\n");
goto exit;
}
/* get sysfs information*/
ret = firmware_sysfs_get_dev_info(fd, &dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "firmware_sysfs_get_dev_info failed, ret %d.\n", ret);
goto exit;
}
/* enable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_INIT, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
goto exit;
}
ret = firmware_upgrade_sysfs_program(&dev_info, dev_info.dev_base, buf, size);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
goto fail;
}
dbg_print(is_debug_on, "firmware upgrade sysfs success.\n");
/* disable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_FINISH,NULL);
if (ret < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
return FIRMWARE_SUCCESS;
fail:
/* disable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_FINISH, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
exit:
dbg_print(is_debug_on, "firmware upgrade sysfs fail.\n");
return FIRMWARE_FAILED;
}
/* sysfs upgrade test function */
int firmware_upgrade_sysfs_test(int fd, name_info_t *info)
{
int ret, rv;
firmware_dev_file_info_t dev_info;
uint8_t *data_buf;
uint8_t num;
int j;
if (info == NULL) {
dbg_print(is_debug_on, "Input invalid error.\n");
return FIRMWARE_FAILED;
}
/* get sysfs information*/
ret = firmware_sysfs_get_dev_info(fd, &dev_info);
if (ret < 0) {
dbg_print(is_debug_on, "firmware_sysfs_get_dev_info failed, ret %d.\n", ret);
return FIRMWARE_FAILED;
}
if (dev_info.test_size == 0) {
dbg_print(is_debug_on, "Error: get sysfs test size:%d, not support.\n", dev_info.test_size);
return FIRMWARE_NOT_SUPPORT;
}
data_buf = (uint8_t *) malloc(dev_info.test_size);
if (data_buf == NULL) {
dbg_print(is_debug_on, "Error: Failed to malloc memory for test data buf, size=%d.\n", dev_info.test_size);
return FIRMWARE_FAILED;
}
/* Get random data */
for (j = 0; j < dev_info.test_size; j++) {
num = (uint8_t) rand() % 256;
data_buf[j] = num & 0xff;
}
/* enable upgrade access */
ret = ioctl(fd, FIRMWARE_SYSFS_INIT, NULL);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
free(data_buf);
return FIRMWARE_FAILED;
}
ret = firmware_upgrade_sysfs_program(&dev_info, dev_info.test_base, data_buf, dev_info.test_size);
/* disable upgrade access */
rv = ioctl(fd, FIRMWARE_SYSFS_FINISH,NULL);
if (rv < 0) {
dbg_print(is_debug_on, "close dev logic en failed.\n");
}
free(data_buf);
if (ret < 0) {
dbg_print(is_debug_on, "init dev logic faile\n");
return FIRMWARE_FAILED;
}
dbg_print(is_debug_on, "firmware upgrade sysfs success.\n");
return FIRMWARE_SUCCESS;
}

View File

@ -0,0 +1,16 @@
#ifndef __FIRMWARE_UPGRADE_SYSFS_H__
#define __FIRMWARE_UPGRADE_SYSFS_H__
#define FIRMWARE_DEV_NAME_LEN (64) /* the macro definition needs to same as FIRMWARE_DEV_NAME_LEN in firmware_sysfs_upgrade.h */
#define FW_SYSFS_RETRY_SLEEP_TIME (10000) /* 10ms */
#define FW_SYSFS_RETRY_TIME (5) /* retry 5 times, 50ms = FW_SYSFS_RETRY_TIME *FW_SYSFS_RETRY_SLEEP_TIME; */
typedef struct firmware_dev_file_info_s {
char sysfs_name[FIRMWARE_DEV_NAME_LEN]; /* sysfs name */
uint32_t dev_base; /* device upgrade base address */
uint32_t per_len; /* The length of bytes per operation */
uint32_t test_base; /* Test device address */
uint32_t test_size; /* Test flash size */
} firmware_dev_file_info_t;
#endif /* End of __FIRMWARE_UPGRADE_SYSFS_H__ */

View File

@ -0,0 +1,90 @@
#ifndef __FW_UPG_SPI_LOGIC_DEV_H__
#define __FW_UPG_SPI_LOGIC_DEV_H__
#define FIRMWARE_FPGA_WORD_LEN (4)
#define FIRMWARE_LOGIC_DEV_NAME_LEN (64) /* the macro definition needs to same as FIRMWARE_DEV_NAME_LEN in firmware_sysfs_upgrade.h */
#define FIRMWARE_SPI_LOGIC_UPG_RETRY_CNT (10)
#define FIRMWARE_SPI_LOGIC_UPG_BUFF_SIZE (256)
#define FIRMWARE_SPI_LOGIC_SECTOR_SIZE (0x10000) /* One sector is 64Kk */
#define FIRMWARE_UPG_RETRY_SLEEP_TIME (10) /* 10us */
#define FIRMWARE_UPG_RETRY_TIME_CNT (1000)
#define FPGA_UPG_WAIT_SPI_RETRY_CNT (100)
#define FPGA_UPG_WAIT_SPI_RETRY_SLEEP_TIME (1000 * 10) /* 10ms */
#define FIRMWARE_FPGA_UPG_RETRY_CNT (100)
/* FPGA upgrades related instruction definitions */
#define FPGA_UPG_INSTRUTION_SE (0xD8)
#define FPGA_UPG_INSTRUTION_RDSR (0x05)
#define FPGA_UPG_INSTRUTION_WREN (0x06)
#define FPGA_UPG_INSTRUTION_PP (0x02)
#define FPGA_UPG_INSTRUTION_FR (0x0B)
#define FPGA_UPG_INSTRUTION_BE (0xC7)
#define FPGA_UPG_STATUS_MASK (0x1)
#define FPGA_UPG_ACCESS_ENABLE (0x3)
#define FPGA_UPG_SPI_STATUS_MASK (0x1)
#define FFPGA_UPG_DATA_SIZE (256)
#define FPGA_UPG_RETRY_TIMES (3)
/* FPGA upgrades the offset of the associated register */
#define FPGA_UPG_STATUS_REG (0x180)
#define FPGA_UPG_SPI_CTRL_REG (0x184)
#define FPGA_UPG_WR_FLASH_STATUS_REG (0x188)
#define FPGA_UPG_RD_FLASH_STATUS_REG (0x18C)
#define FPGA_UPG_INSTRUCTION_REG (0x190)
#define FPGA_UPG_ADDR_REG (0x194)
#define FPGA_UPG_LENGTH_REG (0x198)
#define FPGA_UPG_DEVICE_ID_REG (0x19C)
#define FPGA_UPG_DROP_REQ_NUM_REG (0x1A8)
typedef struct firmware_spi_logic_info_s {
char logic_dev_name[FIRMWARE_LOGIC_DEV_NAME_LEN]; /* Logical device name */
uint32_t flash_base; /* Flash Upgrade Address */
uint32_t ctrl_base; /* SPI upgrade control register base address */
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
} firmware_spi_logic_info_t;
typedef struct firmware_spi_logic_upg_s {
char dev_path[FIRMWARE_LOGIC_DEV_NAME_LEN];
uint32_t flash_base; /* Flash Upgrade Address */
uint32_t ctrl_base; /* SPI upgrade control register base address */
uint32_t status_reg;
uint32_t spi_ctrl_reg;
uint32_t wr_flash_status_reg;
uint32_t rd_flash_status_reg;
uint32_t instruction_reg;
uint32_t addr_reg;
uint32_t length_reg;
uint32_t device_id_reg;
uint32_t drop_reg_num_reg;
uint32_t test_base; /* Test flash address */
uint32_t test_size; /* Test flash size */
}firmware_spi_logic_upg_t;
typedef enum firmware_spi_flash_rv_s {
FW_SPI_FLASH_RV_OK = 0,
FW_SPI_FLASH_STATUS_ERR,
FW_SPI_FLASH_BUSY,
FW_SPI_FLASH_SPI_BUSY,
FW_SPI_FLASH_WR_ENABLE_ERR,
FW_SPI_FLASH_ERASE_ADDR_ERR,
FW_SPI_FLASH_ERASE_SECTOR_ERR,
FW_SPI_FLASH_WR_ERR,
FW_SPI_FLASH_RD_ERR,
FW_SPI_FLASH_PARAM_ERR,
FW_SPI_FLASH_UPG_ERR,
FW_SPI_FLASH_WR_LENGTH_ERR,
FW_SPI_FLASH_WR_ADDR_ERR,
FW_SPI_FLASH_SET_ACCESS_ERR,
FW_SPI_FLASH_DATA_CMP_ERR,
FW_SPI_FLASH_GET_INFO_ERR,
FW_SPI_FLASH_NOT_SUPPORT_TEST,
} firmware_spi_flash_rv_t;
int fpga_test_spi_logic_flash(int argc, char *argv[]);
#endif /* End of __FW_UPG_SPI_LOGIC_DEV_H__ */

View File

@ -0,0 +1,34 @@
/*
*
* debug.h
* firmware upgrade debug switch control
*/
#ifndef __FIRMWARE_UPGRADE_DEBUG_H__
#define __FIRMWARE_UPGRADE_DEBUG_H__
#include <string.h>
#define mem_clear(data, size) memset((data), 0, (size))
#define DEBUG_INFO_LEN 20
#define DEBUG_FILE "/tmp/.firmware_upgrade_debug"
#define DEBUG_ON_ALL "3"
#define DEBUG_ON_INFO "1"
#define DEBUG_OFF_INFO "0"
enum debug_s {
DEBUG_OFF = 0, /* off debug */
DEBUG_APP_ON, /* open app debug */
DEBUG_ALL_ON, /* open all debug */
DEBUG_IGNORE, /* ignore debug */
};
#define dbg_print(debug, fmt, arg...) \
if (debug == DEBUG_APP_ON || debug == DEBUG_ALL_ON) \
{ do{printf(fmt,##arg);} while(0); }
/* firmware upgrade debug switch */
extern int firmware_upgrade_debug(void);
extern int is_debug_on;
#endif /* End of __FIRMWARE_UPGRADE_DEBUG_H__ */

View File

@ -0,0 +1,172 @@
#ifndef __FIRMWARE_APP_H__
#define __FIRMWARE_APP_H__
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <debug.h>
#include <stdint.h>
#define ERR_FW_CHECK_CPLD_UPGRADE (-601) /* File validation error */
#define ERR_FW_CHECK_FPGA_UPGRADE (-602)
#define ERR_FW_MATCH_CPLD_UPGRADE (-603) /* No matching upgrade file found */
#define ERR_FW_MATCH_FPGA_UPGRADE (-604)
#define ERR_FW_SAMEVER_CPLD_UPGRADE (-605) /* the same version */
#define ERR_FW_SAMEVER_FPGA_UPGRADE (-606)
#define ERR_FW_DO_CPLD_UPGRADE (-607) /* upgrade fail */
#define ERR_FW_DO_FPGA_UPGRADE (-608)
#define ERR_FW_UPGRADE (-609) /* other fail */
#define ERR_FW_CHECK_UPGRADE (-610) /* File validation error */
#define ERR_FW_MATCH_UPGRADE (-611) /* No matching upgrade file found */
#define ERR_FW_SAMEVER_UPGRADE (-612) /* the same version */
#define ERR_FW_DO_UPGRADE (-613) /* upgrade fail */
#define ERR_FW_DO_UPGRADE_NOT_SUPPORT (-614) /* upgrade fail */
#define FIRMWARE_NOT_SUPPORT (-2)
#define FIRMWARE_FAILED (-1)
#define FIRMWARE_SUCCESS (0)
#define FIRMWARE_ACTION_CHECK 0
#define FIRMWARE_ACTION_MATCH 1
#define FIRMWARE_ACTION_VERCHECK 2
#define FIRMWARE_ACTION_UPGRADE 3
#define FIRMWARE_ACTION_SUPPORT 4
#define FIRMWARE_UPGRADE_RETRY_CNT (10)
#define FIRMWARE_NAME_LEN (48)
#define FIRMWARE_SLOT_MAX_NUM (16) /* Maximum number of links supported by board cards */
/* Upgrade file headers */
#define MAX_DEV_NUM 10 /* Maximum number of devices to which the upgrade file is applicable */
#define INSMOD_DRIVER 1 /* insmod driver */
#define RMMOD_DRIVER 0 /* rmmod driver */
#define MAX_HEADER_SIZE 1000 /* Upgrade the maximum length of file header information */
#define MAX_HEADER_KV_SIZE 64 /* Upgrade the maximum length of the file header key value */
/* Upgrade file header key values */
#define FILEHEADER_DEVTYPE "DEVTYPE"
#define FILEHEADER_SUBTYPE "SUBTYPE"
#define FILEHEADER_TYPE "TYPE"
#define FILEHEADER_CHAIN "CHAIN"
#define FILEHEADER_CHIPNAME "CHIPNAME"
#define FILEHEADER_VERSION "VERSION"
#define FILEHEADER_FILETYPE "FILETYPE"
#define FILEHEADER_CRC "CRC"
#define FIRMWARE_CPLD_NAME "cpld"
#define FIRMWARE_FPGA_NAME "fpga"
/* ioctl publi command, the same as driver */
#define FIRMWARE_COMMON_TYPE 'C'
#define FIRMWARE_GET_CHIPNAME _IOR(FIRMWARE_COMMON_TYPE, 0, char) /* get the chip name */
#define FIRMWARE_GET_VERSION _IOR(FIRMWARE_COMMON_TYPE, 2, int) /* get version */
#define FIRMWARE_SET_DEBUG_ON _IOW(FIRMWARE_COMMON_TYPE, 3, int) /* debug on */
#define FIRMWARE_SET_DEBUG_OFF _IOW(FIRMWARE_COMMON_TYPE, 4, int) /* debug off */
/* firmware cpld driver ioctl command, the same as "firmware_driver\firmware_driver\include\firmware.h" */
#define FIRMWARE_TYPE 'J'
#define FIRMWARE_PROGRAM _IOW(FIRMWARE_TYPE, 1, char) /* firmware upgrade ISC */
#define FIRMWARE_READ_CHIP _IOR(FIRMWARE_TYPE, 5, int) /* read the contents of the chip */
#define FIRMWARE_PROGRAM_JBI _IOW(FIRMWARE_TYPE, 6, char) /* firmware upgrade JBI */
/* firmware cpld ispvme driver ioctl command, the same as "firmware_driver\firmware_driver_ispvme\include\firmware_ispvme.h" */
#define FIRMWARE_VME_TYPE 'V'
#define FIRMWARE_JTAG_TDI _IOR(FIRMWARE_VME_TYPE, 0, char)
#define FIRMWARE_JTAG_TDO _IOR(FIRMWARE_VME_TYPE, 1, char)
#define FIRMWARE_JTAG_TCK _IOR(FIRMWARE_VME_TYPE, 2, char)
#define FIRMWARE_JTAG_TMS _IOR(FIRMWARE_VME_TYPE, 3, char)
#define FIRMWARE_JTAG_EN _IOR(FIRMWARE_VME_TYPE, 4, char)
#define FIRMWARE_JTAG_INIT _IOR(FIRMWARE_VME_TYPE, 7, char) /* enable upgrade access */
#define FIRMWARE_JTAG_FINISH _IOR(FIRMWARE_VME_TYPE, 8, char) /* disable upgrade access */
/* firmware sysfs driver ioctl command, the same as "firmware_driver\firmware_driver_sysfs\include\firmware_sysfs.h" */
#define FIRMWARE_SYSFS_TYPE 'S'
#define FIRMWARE_SYSFS_INIT _IOR(FIRMWARE_SYSFS_TYPE, 0, char) /* enable upgrade access */
#define FIRMWARE_SYSFS_FINISH _IOR(FIRMWARE_SYSFS_TYPE, 1, char) /* disable upgrade access */
#define FIRMWARE_SYSFS_SPI_INFO _IOR(FIRMWARE_SYSFS_TYPE, 2, char) /* spi flash upgrade */
#define FIRMWARE_SYSFS_DEV_FILE_INFO _IOR(FIRMWARE_SYSFS_TYPE, 3, char) /* sysfs upgrade */
#define FIRMWARE_SYSFS_MTD_INFO _IOR(FIRMWARE_SYSFS_TYPE, 4, char) /* sysfs mtd upgrade */
/* VME file, used to distinguish the JTAG signal that needs to operate */
#define JTAG_TDO 1
#define JTAG_TCK 2
#define JTAG_TDI 3
#define JTAG_TMS 4
#define JTAG_ENABLE 5
#define JTAG_TRST 6
typedef struct name_info_s {
int card_type[MAX_DEV_NUM]; /* main board type */
int sub_type[MAX_DEV_NUM]; /* sub board type */
int type; /* device type */
int chain; /* chain num */
char chip_name[FIRMWARE_NAME_LEN]; /* chip name */
char version[FIRMWARE_NAME_LEN]; /* version */
int file_type; /* file type */
unsigned int crc32; /* 4 byte CRC values */
} name_info_t;
typedef struct cmd_info_s {
uint32_t size;
void *data;
} cmd_info_t;
enum firmware_type_s {
FIRMWARE_UNDEF_TYPE = 0,
FIRMWARE_CPLD,
FIRMWARE_FPGA,
FIRMWARE_SYSFS,
FIRMWARE_OTHER,
};
typedef enum firmware_file_type_s {
FIRMWARE_UNDEF_FILE_TYPE = 0,
FIRMWARE_VME, /* ispvme cpld, GPIO simulates JTAG */
FIRMWARE_ISC, /* cpld, GPIO simulates JTAG */
FIRMWARE_JBI,
FIRMWARE_SPI_LOGIC_DEV, /* FPGA SPI upgrde register upgrade flash */
FIRMWARE_SYSFS_DEV, /* write file upgrade eeprom */
FIRMWARE_MTD, /* upgrade mtd device */
FIRMWARE_NONE,
} firmware_file_type_t;
typedef struct firmware_file_name_s {
char firmware_file_name_str[MAX_HEADER_KV_SIZE];
int firmware_file_type;
} firmware_file_name_t;
extern int header_offset;
/* CRC32 calculation */
extern unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len);
/* VME file upgrade */
extern int firmware_upgrade_ispvme(int file_fd, char *upgrade_file_name, name_info_t *info);
extern void writePort(unsigned char a_ucPins, unsigned char a_ucValue);
extern unsigned char readPort();
extern void sclock();
extern void ispVMStateMachine(signed char NextState);
/* spi flash upgrade */
extern int firmware_upgrade_spi_logic_dev(int fd, uint8_t *buf, uint32_t size, name_info_t *info);
/* spi flash upgrade test*/
extern int firmware_upgrade_spi_logic_dev_test(int fd, name_info_t *info);
/* spi flash data print*/
extern int firmware_upgrade_spi_logic_dev_dump(char *dev_name, uint32_t offset, uint32_t size, char *record_file);
/* sysfs upgrade */
extern int firmware_upgrade_sysfs(int fd, uint8_t *buf, uint32_t size, name_info_t *info);
/* sysfs upgrade test*/
extern int firmware_upgrade_sysfs_test(int fd, name_info_t *info);
/* isc upgrade */
extern int firmware_upgrade_jtag(int fd, uint8_t *buf, uint32_t size, name_info_t *info);
/* isc upgrade test */
extern int firmware_upgrade_jtag_test(int fd, uint8_t *buf, uint32_t size, name_info_t *info);
/* mtd upgrade */
extern int firmware_upgrade_mtd(int fd, uint8_t *buf, uint32_t size, name_info_t *info);
/* mtd upgrade test */
extern int firmware_upgrade_mtd_test(int fd, name_info_t *info);
#endif /* End of __FIRMWARE_APP_H__ */

View File

@ -0,0 +1,192 @@
/***************************************************************
*
* This is the include file for Lattice Semiconductor's ispVM
* Embedded software application.
*
***************************************************************/
/***************************************************************
*
* VME version.
*
* History:
*
***************************************************************/
#define VME_VERSION_NUMBER "12.2"
/***************************************************************
*
* Maximum declarations.
*
***************************************************************/
#define VMEHEXMAX 60000L /* The hex file is split 60K per file. */
#define SCANMAX 64000L /* The maximum SDR/SIR burst. */
/***************************************************************
*
* Supported JTAG state transitions.
*
***************************************************************/
#define RESET 0x00
#define IDLE 0x01
#define IRPAUSE 0x02
#define DRPAUSE 0x03
#define SHIFTIR 0x04
#define SHIFTDR 0x05
#define DRCAPTURE 0x06
/***************************************************************
*
* Flow control register bit definitions. A set bit indicates
* that the register currently exhibits the corresponding mode.
*
***************************************************************/
#define INTEL_PRGM 0x0001 /* Intelligent programming is in effect. */
#define CASCADE 0x0002 /* Currently splitting large SDR. */
#define REPEATLOOP 0x0008 /* Currently executing a repeat loop. */
#define SHIFTRIGHT 0x0080 /* The next data stream needs a right shift. */
#define SHIFTLEFT 0x0100 /* The next data stream needs a left shift. */
#define VERIFYUES 0x0200 /* Continue if fail is in effect. */
/***************************************************************
*
* DataType register bit definitions. A set bit indicates
* that the register currently holds the corresponding type of data.
*
***************************************************************/
#define EXPRESS 0x0001 /* Simultaneous program and verify. */
#define SIR_DATA 0x0002 /* SIR is the active SVF command. */
#define SDR_DATA 0x0004 /* SDR is the active SVF command. */
#define COMPRESS 0x0008 /* Data is compressed. */
#define TDI_DATA 0x0010 /* TDI data is present. */
#define TDO_DATA 0x0020 /* TDO data is present. */
#define MASK_DATA 0x0040 /* MASK data is present. */
#define HEAP_IN 0x0080 /* Data is from the heap. */
#define LHEAP_IN 0x0200 /* Data is from intel data buffer. */
#define VARIABLE 0x0400 /* Data is from a declared variable. */
#define CRC_DATA 0x0800 /* CRC data is pressent. */
#define CMASK_DATA 0x1000 /* CMASK data is pressent. */
#define RMASK_DATA 0x2000 /* RMASK data is pressent. */
#define READ_DATA 0x4000 /* READ data is pressent. */
#define DMASK_DATA 0x8000 /* DMASK data is pressent. */
/***************************************************************
*
* Pin opcodes.
*
***************************************************************/
#define signalENABLE 0x1C /* ispENABLE pin. */
#define signalTMS 0x1D /* TMS pin. */
#define signalTCK 0x1E /* TCK pin. */
#define signalTDI 0x1F /* TDI pin. */
#define signalTRST 0x20 /* TRST pin. */
/***************************************************************
*
* Supported vendors.
*
***************************************************************/
#define VENDOR 0x56
#define LATTICE 0x01
#define ALTERA 0x02
#define XILINX 0x03
/***************************************************************
*
* Opcode definitions.
*
* Note: opcodes must be unique.
*
***************************************************************/
#define ENDDATA 0x00 /* The end of the current SDR data stream. */
#define RUNTEST 0x01 /* The duration to stay at the stable state. */
#define ENDDR 0x02 /* The stable state after SDR. */
#define ENDIR 0x03 /* The stable state after SIR. */
#define ENDSTATE 0x04 /* The stable state after RUNTEST. */
#define TRST 0x05 /* Assert the TRST pin. */
#define HIR 0x06 /* The sum of the IR bits of the leading devices. */
#define TIR 0x07 /* The sum of the IR bits of the trailing devices. */
#define HDR 0x08 /* The number of leading devices. */
#define TDR 0x09 /* The number of trailing devices. */
#define ispEN 0x0A /* Assert the ispEN pin. */
#define FREQUENCY 0x0B /* The maximum clock rate to run the JTAG state machine. */
#define STATE 0x10 /* Move to the next stable state. */
#define SIR 0x11 /* The instruction stream follows. */
#define SDR 0x12 /* The data stream follows. */
#define TDI 0x13 /* The following data stream feeds into the device. */
#define TDO 0x14 /* The following data stream is compared against the device. */
#define MASK 0x15 /* The following data stream is used as mask. */
#define XSDR 0x16 /* The following data stream is for simultaneous program and verify. */
#define XTDI 0x17 /* The following data stream is for shift in only. It must be stored for the next XSDR. */
#define XTDO 0x18 /* There is not data stream. The data stream was stored from the previous XTDI. */
#define MEM 0x19 /* The maximum memory needed to allocate in order hold one row of data. */
#define WAIT 0x1A /* The duration of delay to observe. */
#define TCK 0x1B /* The number of TCK pulses. */
#define SHR 0x23 /* Set the flow control register for right shift. */
#define SHL 0x24 /* Set the flow control register for left shift. */
#define HEAP 0x32 /* The memory size needed to hold one loop. */
#define REPEAT 0x33 /* The beginning of the loop. */
#define LEFTPAREN 0x35 /* The beginning of data following the loop. */
#define VAR 0x55 /* Plac holder for loop data. */
#define SEC 0x1C /* The delay time in seconds that must be observed. */
#define SMASK 0x1D /* The mask for TDI data. */
#define MAX 0x1E /* The absolute maximum wait time. */
#define ON 0x1F /* Assert the targeted pin. */
#define OFF 0x20 /* Dis-assert the targeted pin. */
#define SETFLOW 0x30 /* Change the flow control register. */
#define RESETFLOW 0x31 /* Clear the flow control register. */
#define CRC 0x47 /* The following data stream is used for CRC calculation. */
#define CMASK 0x48 /* The following data stream is used as mask for CRC calculation. */
#define RMASK 0x49 /* The following data stream is used as mask for read and save. */
#define READ 0x50 /* The following data stream is used for read and save. */
#define ENDLOOP 0x59 /* The end of the repeat loop. */
#define SECUREHEAP 0x60 /* Used to secure the HEAP opcode. */
#define VUES 0x61 /* Support continue if fail. */
#define DMASK 0x62 /* The following data stream is used for dynamic I/O. */
#define COMMENT 0x63 /* Support SVF comments in the VME file. */
#define HEADER 0x64 /* Support header in VME file. */
#define FILE_CRC 0x65 /* Support crc-protected VME file. */
#define LCOUNT 0x66 /* Support intelligent programming. */
#define LDELAY 0x67 /* Support intelligent programming. */
#define LSDR 0x68 /* Support intelligent programming. */
#define LHEAP 0x69 /* Memory needed to hold intelligent data buffer */
#define CONTINUE 0x70 /* Allow continuation. */
#define LVDS 0x71 /* Support LVDS. */
#define ENDVME 0x7F /* End of the VME file. */
#define HIGH 0x80 /* Assert the targeted pin. */
#define LOW 0x81 /* Dis-assert the targeted pin. */
#define ENDFILE 0xFF /* End of file. */
/***************************************************************
*
* ispVM Embedded Return Codes.
*
***************************************************************/
#define VME_VERIFICATION_FAILURE -1
#define VME_FILE_READ_FAILURE -2
#define VME_VERSION_FAILURE -3
#define VME_INVALID_FILE -4
#define VME_ARGUMENT_FAILURE -5
#define VME_CRC_FAILURE -6
/***************************************************************
*
* Type definitions.
*
***************************************************************/
/* Support LVDS */
typedef struct {
unsigned short usPositiveIndex;
unsigned short usNegativeIndex;
unsigned char ucUpdate;
} LVDSPair;

View File

@ -0,0 +1,18 @@
top_srcdir:=$(shell pwd)
include $(top_srcdir)/Rules.mk
firmware-y:=
firmware-y += fw_upgrade
.PHONY: all
all: build
.PHONY: build
build: $(firmware-y)
$(foreach dir,$(firmware-y),$(eval $(call compile_dirs,$(dir))))
.PHONY: rpmpkg
rpmpkg:
ifeq ("$(CONFIG_CPLD_UPGRADE_ISPVME)", "y")
#$(RPMPKG) $(install_cpld_dir) firmware-cpld-ispvme.spec git
endif

View File

@ -0,0 +1,42 @@
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
AS ?= $(CROSS)as
LD ?= $(CROSS)ld
STRIP ?= $(CROSS)strip
install_root:=${top_srcdir}/images
install_header_dir:=${install_root}/header
install_adir:=$(install_root)/lib
install_symbol_dir:=$(install_root)/symbol
symbol_files:=$(shell find $(EXPORT_SYMBOL) -name 'Module.symvers')
#
# symbol_files += $(shell find $(install_symbol_dir) -name 'Module.symvers')
# KBUILD_EXTRA_SYMBOLS += $(symbol_files)
# export KBUILD_EXTRA_SYMBOLS
# top root: install_rootfs_dir
install_rootfs_dir:=$(install_root)/rootfs
install_sodir:=$(install_rootfs_dir)/$(INSTALL_SODIR)
install_usr_bin_dir:=$(install_rootfs_dir)/usr/bin
install_sbin_dir:=$(install_rootfs_dir)/sbin
install_etc_dir:=$(install_rootfs_dir)/etc
export INSTALL_MOD_PATH:=$(ROOT)
BUILD_CFLAGS:=$(CFLAGS) -I$(install_header_dir)
BUILD_LDFLAGS:=$(LDFLAGS) -L/$(install_sodir) -L/$(install_adir)
define compile_dirs
.PHONY: $(1)
$(1):
@echo;echo "building $(1)..."
@$(MAKE) -C ${1}
endef
compile.c = $(CC) $(BUILD_CFLAGS) -d -c -o $@ $<
%.o: %.c
$(compile.c)

View File

@ -0,0 +1,39 @@
include ../Rules.mk
OBJ = fw_upgrade.o fw_upgrade_debug.o
LIB += $(BUILD_CFALGS) $(BUILD_LDFLAGS) -lpthread
ifdef ENABLE_GCOV
ifeq ($(ENABLE_GCOV), y)
LIB += -fprofile-arcs
endif
endif # ENABLE_GCOV
APP = fw_upgrade
BUILD_DIR = tmp
ELF_FILE = $(BUILD_DIR)/$(APP)
MAP_FILE = $(BUILD_DIR)/$(APP).map.sym
INCLUDE = -Iinclude
CFLAGS+=-Wall -W -g
.PHONY: build
build:make-dir $(addprefix $(BUILD_DIR)/,$(OBJ))
$(CC) -o $(ELF_FILE) $(addprefix $(BUILD_DIR)/,$(OBJ)) $(LINKFLAGS) $(LIB)
cp -p $(ELF_FILE) $(common_out_put_dir)
.PHONY: make-dir
make-dir:
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o:%.c
$(CC) -c $(CFLAGS) $(INCLUDE) $< -o $@
.PHONY: install
install:
echo "fw_upgrade install success."
cp -p $(ELF_FILE) $(common_out_put_dir)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)

View File

@ -0,0 +1,51 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <ctype.h>
#include "fw_upgrade_debug.h"
int fw_upgrade_debug(void)
{
int size;
FILE *fp;
char debug_info[DEBUG_INFO_LEN];
fp = fopen(DEBUG_FILE, "r");
if (fp == NULL) {
return DEBUG_IGNORE;
}
mem_clear(debug_info, DEBUG_INFO_LEN);
size = fread(debug_info, DEBUG_INFO_LEN - 1, 1, fp);
if (size < 0) {
fclose(fp);
return DEBUG_IGNORE;
}
if (strncmp(debug_info, DEBUG_ON_INFO, 1) == 0) {
fclose(fp);
return DEBUG_APP_ON;
}
if (strncmp(debug_info, DEBUG_ON_KERN, 1) == 0) {
fclose(fp);
return DEBUG_KERN_ON;
}
if (strncmp(debug_info, DEBUG_ON_ALL, 1) == 0) {
fclose(fp);
return DEBUG_ALL_ON;
}
if (strncmp(debug_info, DEBUG_OFF_INFO, 1) == 0) {
fclose(fp);
return DEBUG_OFF;
}
fclose(fp);
return DEBUG_IGNORE;
}

View File

@ -0,0 +1,230 @@
#ifndef _FW_UPGRADE_H_
#define _FW_UPGRADE_H_
#include "fw_upgrade_debug.h"
#define dbg_print(debug, fmt, arg...) \
if (debug == DEBUG_APP_ON || debug == DEBUG_ALL_ON) \
{ do{printf(fmt,##arg);} while(0); }
/* LPC Interface */
#define LPC_ADDR_PORT (0x4E)
#define LPC_DATA_PORT (0x4F)
/* FMC REGISTER ADDR */
#define FMC_BASE_ADDR (0x1E620000)
#define FMC_CE_TYPE_SETTING_REG (FMC_BASE_ADDR + 0x00)
#define CE_CONTROL_REGISTER (FMC_BASE_ADDR + 0x04)
#define INR_STATUS_CONTROL_REGISTER (FMC_BASE_ADDR + 0x08)
#define COMMAND_CONTROL_REGISTER (FMC_BASE_ADDR + 0x0C)
#define CE0_CONTROL_REGISTER (FMC_BASE_ADDR + 0x10)
#define CE1_CONTROL_REGISTER (FMC_BASE_ADDR + 0x14)
#define CE0_ADDRESS_RANGE_REGISTER (FMC_BASE_ADDR + 0x30)
#define CE1_ADDRESS_RANGE_REGISTER (FMC_BASE_ADDR + 0x34)
/* SCU REGISTER ADDR */
#define SCU_ADDR (0x1E6E2000)
#define HARDWARE_STRAP_REGISTER (SCU_ADDR + 0x70)
#define REBOOT_CPU_REGISTER (SCU_ADDR + 0x7C)
/* SCU KEY */
#define UNLOCK_SCU_KEY (0x1688A8A8)
#define LOCK_SCU_KEY (0x11111111)
/* WATCHDOG REGISTER ADDR */
#define WATCHDOG_ADDR (0x1E785000)
#define WATCHDOG1_RELOAD_VALUE (WATCHDOG_ADDR + 0x04)
#define WATCHDOG1_COUNTER_RST (WATCHDOG_ADDR + 0x08)
#define WATCHDOG1_CONTROL (WATCHDOG_ADDR + 0x0C)
#define WATCHDOG1_TSR (WATCHDOG_ADDR + 0x10)
#define WATCHDOG1_CLEAR_STATUS (WATCHDOG_ADDR + 0x14)
#define WATCHDOG1_RESET_FUN_MASK (WATCHDOG_ADDR + 0x1C)
#define WATCHDOG2_RELOAD_VALUE (WATCHDOG_ADDR + 0x24)
#define WATCHDOG2_COUNTER_RST (WATCHDOG_ADDR + 0x28)
#define WATCHDOG2_CONTROL (WATCHDOG_ADDR + 0x2C)
#define WATCHDOG2_TSR (WATCHDOG_ADDR + 0x30)
#define WATCHDOG2_CLEAR_STATUS (WATCHDOG_ADDR + 0x34)
#define WATCHDOG2_RESET_FUN_MASK (WATCHDOG_ADDR + 0x3C)
/* User Mode Command */
#define WRITE_STATUS (0x01)
#define COMMON_PAGE_PROGRAM (0x02)
#define COMMON_FLASH_READ (0x03)
#define WRITE_DISABLE_FLASH (0x04)
#define READ_FLASH_STATUS (0x05)
#define WRITE_ENABLE_FLASH (0x06)
#define PAGE_PROGRAM_FLASH (0x12)
#define SECTOR_ERASE (0x20)
#define CLEAR_FLAG (0x50)
#define SUBBLOCK_ERASE (0x52)
#define CHIP_ERASE_FLASH (0x60)
#define BLOCK_ERASE_64 (0xD8)
#define READID (0x9F)
#define ENABLE_BYTE4 (0xB7)
#define EXIT_OTP (0xC1)
#define RSTEN (0x66)
#define RST (0x99)
#define BIT1 (0x01)
#define BIT2 (0x02)
#define BIT3 (0x04)
#define BIT4 (0x08)
#define BIT5 (0x10)
#define BIT6 (0x20)
#define BIT7 (0x40)
#define BIT8 (0x80)
#define RIGHT_SHIFT_8(reg) (reg >> 8)
#define RIGHT_SHIFT_16(reg) (reg >> 16)
#define RIGHT_SHIFT_24(reg) (reg >> 24)
#define MASK (0xFF)
#define FLASH_TYPE_MASK (BIT1 | BIT2)
#define BOOT_DEFAULT_MASK (BIT8)
#define HEAD_MASK (0x00FFFF00)
#define MASK_BYTE (0xFF000000)
#define BYTE1 (1)
#define BYTE2 (2)
#define BYTE4 (4)
#define BYTE1_VAL (0)
#define BYTE2_VAL (1)
#define BYTE4_VAL (2)
#define BYTE_RESERVED (3)
/* SuperIO */
#define SUPERIO_07 (0x07)
#define SUPERIO_30 (0x30)
#define SUPERIO_A0 (0xA0)
#define SUPERIO_A2 (0xA2)
#define SUPERIO_REG0 (0xF0)
#define SUPERIO_REG1 (0xF1)
#define SUPERIO_REG2 (0xF2)
#define SUPERIO_REG3 (0xF3)
#define SUPERIO_REG4 (0xF4)
#define SUPERIO_REG5 (0xF5)
#define SUPERIO_REG6 (0xF6)
#define SUPERIO_REG7 (0xF7)
#define SUPERIO_REG8 (0xF8)
#define SUPERIO_FE (0xFE)
/* SPI Command */
#define HIGH_CLOCK (0x00000000)
#define NORMAL_READ (0x00000000)
#define READ_MODE (0x00000001)
#define WRITE_MODE (0x00000002)
#define USER_MODE (0x00000003)
#define PULL_DOWN (0x00000000)
#define PULL_UP (0x00000004)
#define CHIP_ERASE_TIME (60)
#define CHIP_ERASE_TIMEOUT (300 * 1000 * 1000)
#define CHIP_ERASE_SLEEP_TIME (5 * 1000 * 1000)
#define BLOCK_ERASE_TIMEOUT (10 * 1000 * 1000)
#define BLOCK_ERASE_SLEEP_TIME (100 * 1000)
#define PAGE_PROGRAM_TIMEOUT (100 * 1000)
#define PAGE_PROGRAM_SLEEP_TIME (1000)
#define FLASH_WEL_TIMEOUT (100 * 1000)
#define FLASH_WEL_SLEEP_TIME (1000)
#define FLASH_WIP_MASK (0x00000001)
#define FLASH_WRITE_ENABLE_MASK (0x00000002)
#define DATA_LENGTH_MASK (0xA2)
#define TOGGLE_WRITE (0xCF)
#define DISABLE_LPC (0xAA)
#define ENABLE_LPC (0xA5)
#define LPC_TO_AHB (0x0D)
#define ENABLE_LPC_TO_AHB (0x01)
#define DISABLE_LPC_TO_AHB (0x00)
#define ENABLE_BMC_CPU_BOOT (0xF10BD286)
#define DISABLE_BMC_CPU_BOOT (0xF10BD287)
#define SET_BMC_CPU_BOOT (0x01)
#define CLEAR_WATCHDOG_STATUS (0x01)
#define DISABLE_WATCHDOG (0x00000030)
#define ENABLE_WATCHDOG (0x00000033)
#define WATCHDOG_GATEMASK (0x033FFFF3)
#define WATCHDOG_NEW_COUNT (0x00050000)
#define WATCHDOG_RELOAD_COUNTER (0x4755)
#define CE0_SPI_TYPE (0x00000002)
#define CE1_SPI_TYPE (0x00000008)
#define ERROR_COMMAND (0x00000400)
#define ADDRESS_PROTECT (0x00000200)
#define CLEAR_INR_STATUS_CONTROL (ERROR_COMMAND | ADDRESS_PROTECT)
#define USER_MODE_PULL_CE_DOWN (HIGH_CLOCK | USER_MODE | PULL_DOWN)
#define USER_MODE_PULL_CE_UP (HIGH_CLOCK | USER_MODE | PULL_UP)
#define STEP_64 (64 * 1024)
#define STEP_256 (256 * 1024)
#define BYTE_256 (256)
#define CE0 (0)
#define CE1 (1)
#define BOTHFLASH (2)
#define SOC_SYS (0)
#define FULL_CHIP (1)
#define ARM_CPU (2)
#define FULL_ERASE (0)
#define BLOCK_ERASE (1)
#define READ_ALL (2)
#define CURRENT_SLAVE (1)
#define CURRENT_MASTER (0)
#define REGISTER_HEAD (0x1e000000)
#define DEFAULT_WIDTH (16)
#define MAX_FILENAME_LENGTH (64)
#define SEGMENT_ADDR_START(_r) ((((_r) >> 16) & 0xFF) << 23)
typedef struct flash_info {
uint32_t flash_size;
int cs;
int flash_type;
uint32_t flash_id;
int page_size;
char flash_name[64];
int erase_block_command;
int page_program;
int block_size;
int full_erase;
uint32_t ce_control_reg;
uint32_t flash_base_addr;
} flash_info_t;
typedef enum flash_id {
MX25L6433F = 0x1920c2,
S25FL512S = 0x200201,
MX25l512 = 0x1a20c2,
STM25P64 = 0x172020,
STM25P128 = 0x182020,
N25Q256 = 0x19ba20,
N25Q512 = 0x20ba20,
W25X16 = 0x1530ef,
W25X64 = 0x1730ef,
W25Q64BV = 0x1740ef,
W25Q128BV = 0x1840ef,
W25Q256FV = 0x1940ef,
MX25L1605D = 0x1520C2,
MX25L12805D = 0x1820C2,
MX66L1G45G = 0x1B20C2,
SST25VF016B = 0x4125bf,
SST25VF064C = 0x4b25bf,
SST25VF040B = 0x8d25bf,
AT25DF161 = 0x02461F,
AT25DF321 = 0x01471F,
GD25Q256 = 0X1940c8,
} flash_id_t;
typedef enum flash_type {
NOR = 0,
SPI = 2,
} flash_type_t;
typedef enum flash_size {
M1 = 0x00080000,
M3 = 0x00200000, /* 3M */
M6 = 0x00400000, /* 6M */
M12 = 0x00800000, /* 12M */
M16 = 0x01000000, /* 16M */
M32 = 0x02000000, /* 32M */
M64 = 0x04000000, /* 64M */
M128 = 0x08000000, /* 128M */
} flash_size_t;
#endif /*_FW_UPGRADE_H_*/

View File

@ -0,0 +1,25 @@
#ifndef __FW_UPGRADE_DEBUG_H__
#define __FW_UPGRADE_DEBUG_H__
#include <string.h>
#define DEBUG_INFO_LEN 20
#define DEBUG_FILE "/tmp/.fw_upgrade_debug"
#define DEBUG_ON_ALL "3"
#define DEBUG_ON_KERN "2"
#define DEBUG_ON_INFO "1"
#define DEBUG_OFF_INFO "0"
#define mem_clear(data, size) memset((data), 0, (size))
enum debug_s {
DEBUG_OFF = 0,
DEBUG_APP_ON,
DEBUG_KERN_ON,
DEBUG_ALL_ON,
DEBUG_IGNORE,
};
extern int fw_upgrade_debug(void);
#endif /* End of __FW_UPGRADE_DEBUG_H__ */

View File

@ -1,4 +0,0 @@
# depmod.conf
#
# override default search ordering for kmod packaging
search updates extra external built-in weak-updates

Some files were not shown because too many files have changed in this diff Show More