diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini
index 823f53160c..b71ad39648 100755
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/port_config.ini
@@ -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
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/td3-ra-b6510-48v8c-48x25G+8x100G.config.bcm b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/td3-ra-b6510-48v8c-48x25G+8x100G.config.bcm
index 27656bd3d4..e86eb1b9fa 100644
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/td3-ra-b6510-48v8c-48x25G+8x100G.config.bcm
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/RA-B6510-48V8C/td3-ra-b6510-48v8c-48x25G+8x100G.config.bcm
@@ -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
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin
index 1fe5585e07..e02f94e7ed 100644
Binary files a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin and b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/custom_led.bin differ
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml
old mode 100755
new mode 100644
index f5e8715643..3bdd16e803
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev.xml
@@ -7,116 +7,413 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev_exhaust.xml b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev_exhaust.xml
new file mode 100644
index 0000000000..c6c4852077
--- /dev/null
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/dev_exhaust.xml
@@ -0,0 +1,419 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/fru.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/fru.py
new file mode 100644
index 0000000000..f95164e036
--- /dev/null
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/fru.py
@@ -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)
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/bios_upgrade_header.bin b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/bios_upgrade_header.bin
new file mode 100644
index 0000000000..08eba59b3a
Binary files /dev/null and b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/bios_upgrade_header.bin differ
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/cpu_cpld_upgrade_header.vme b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/cpu_cpld_upgrade_header.vme
new file mode 100644
index 0000000000..83f6b99d2a
Binary files /dev/null and b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/cpu_cpld_upgrade_header.vme differ
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/fpga_upgrade_header.bin b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/fpga_upgrade_header.bin
new file mode 100644
index 0000000000..675ffa24dc
Binary files /dev/null and b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/fpga_upgrade_header.bin differ
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme
new file mode 100644
index 0000000000..7be3d61ea2
Binary files /dev/null and b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/latest_firmware/other_cpld_upgrade_header.vme differ
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py
old mode 100755
new mode 100644
index 103a2f30ac..e300df137e
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/monitor.py
@@ -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)
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml
index 90ebf17406..7b026cec39 100644
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pcie.yaml
@@ -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'
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pd-plugin.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pd-plugin.json
deleted file mode 100644
index ffa06ff743..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pd-plugin.json
+++ /dev/null
@@ -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"
- }
-}
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pddf-device.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pddf-device.json
deleted file mode 100644
index e9fc701bb8..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf/pddf-device.json
+++ /dev/null
@@ -1,6502 +0,0 @@
-{
- "PLATFORM": {
- "num_psus": 2,
- "num_fantrays": 4,
- "num_fans_pertray": 1,
- "num_ports": 56,
- "num_temps": 3,
- "pddf_dev_types": {
- "description": "RA-B6510-48v8c",
- "CPLD": [
- "i2c_cpld"
- ],
- "PSU": [
- "psu_eeprom",
- "psu_pmbus"
- ],
- "FAN": [
- "fan_ctrl",
- "fan_cpld",
- "fan_eeprom"
- ],
- "PORT_MODULE": [
- "pddf_xcvr",
- "optoe1",
- "optoe2"
- ]
- },
- "std_kos": [
- "i2c-ismt",
- "i2c-i801",
- "i2c_dev",
- "i2c_gpio",
- "i2c_algo_bit",
- "i2c_mux_pca9641",
- "i2c_mux_pca954x force_create_bus=1 close_chan_force_reset=1",
- "lm75",
- "optoe",
- "at24",
- "pmbus_core"
- ],
- "pddf_kos": [
- "pddf_client_module",
- "pddf_cpld_module",
- "pddf_cpld_driver",
- "pddf_mux_module",
- "pddf_xcvr_module",
- "pddf_xcvr_driver_module",
- "pddf_psu_driver_module",
- "pddf_psu_module",
- "pddf_fan_driver_module",
- "pddf_fan_module",
- "pddf_led_module",
- "pddf_sysstatus_module"
- ],
- "custom_kos": [
- "ragile_platform",
- "ragile_common dfd_my_type=0x404a",
- "rg_cpld",
- "rg_fan",
- "rg_psu",
- "rg_gpio_xeon",
- "csu550"
- ]
-
- },
-
- "SYSTEM": {
- "dev_info": {
- "device_type": "CPU",
- "device_name": "ROOT_COMPLEX",
- "device_parent": null
- },
- "i2c": {
- "CONTROLLERS": [{
- "dev_name": "i2c-0",
- "dev": "SMBUS0"
- }, {
- "dev_name": "i2c-2",
- "dev": "SMBUS1"
- }, {
- "dev_name": "i2c-1",
- "dev": "I2C-GPIO0"
- }]
- }
- },
-
- "SMBUS0": {
- "dev_info": {
- "device_type": "SMBUS",
- "device_name": "SMBUS0",
- "device_parent": "SYSTEM"
- },
- "i2c": {
- "topo_info": {
- "dev_addr": "0x0"
- },
- "DEVICES": [{
- "dev": "CPU_CPLD"
- },
- {
- "dev": "CONNECT_BOARD_CPLD1"
- }
- ]
- }
- },
-
- "CPU_CPLD": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "CPU_CPLD",
- "device_parent": "SMBUS0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x0",
- "dev_addr": "0x0d",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "CONNECT_BOARD_CPLD1": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "CONNECT_BOARD_CPLD1",
- "device_parent": "SMBUS0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x0",
- "dev_addr": "0x32",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "SMBUS1": {
- "dev_info": {
- "device_type": "SMBUS",
- "device_name": "SMBUS1",
- "device_parent": "SYSTEM"
- },
- "i2c": {
- "topo_info": {
- "dev_addr": "0x2"
- },
- "DEVICES": [{
- "dev": "MAC_BOARD_CPLD1_A"
- },
- {
- "dev": "MAC_BOARD_CPLD2_A"
- },
- {
- "dev": "CONNECT_BOARD_CPLD2"
- },
- {
- "dev": "FAN-CTRL"
- },
- {
- "dev": "TEMP1"
- },
- {
- "dev": "TEMP2"
- },
- {
- "dev": "TEMP3"
- },
- {
- "dev": "EEPROM1"
- },
- {
- "dev": "MUX1"
- }
- ]
- }
- },
-
- "MAC_BOARD_CPLD1_A": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "MAC_BOARD_CPLD1_A",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x33",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "MAC_BOARD_CPLD2_A": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "MAC_BOARD_CPLD2_A",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x35",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "FAN-CTRL": {
- "dev_info": {
- "device_type": "FAN",
- "device_name": "FAN-CTRL",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x66",
- "dev_type": "fan_cpld"
- },
- "dev_attr": {
- "num_fantrays": "4"
- },
- "attr_list": [{
- "attr_name": "fan1_present",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x30",
- "attr_mask": "0x1",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "fan2_present",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x30",
- "attr_mask": "0x2",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "fan3_present",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x30",
- "attr_mask": "0x4",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "fan4_present",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x30",
- "attr_mask": "0x8",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "fan1_input",
- "attr_devname": "CONNECT_BOARD_CPLD2",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x1b",
- "attr_mult": "1",
- "attr_len": "2"
- },
- {
- "attr_name": "fan2_input",
- "attr_devname": "CONNECT_BOARD_CPLD2",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x1d",
- "attr_mult": "1",
- "attr_len": "2"
- },
- {
- "attr_name": "fan3_input",
- "attr_devname": "CONNECT_BOARD_CPLD2",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x1f",
- "attr_mult": "1",
- "attr_len": "2"
- },
- {
- "attr_name": "fan4_input",
- "attr_devname": "CONNECT_BOARD_CPLD2",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x37",
- "attr_offset": "0x21",
- "attr_mult": "1",
- "attr_len": "2"
- },
- {
- "attr_name": "fan1_pwm",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x32",
- "attr_offset": "0x15",
- "attr_mask": "0xff",
- "attr_len": "1"
- },
- {
- "attr_name": "fan2_pwm",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x32",
- "attr_offset": "0x15",
- "attr_mask": "0xff",
- "attr_len": "1"
- },
- {
- "attr_name": "fan3_pwm",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x32",
- "attr_offset": "0x15",
- "attr_mask": "0xff",
- "attr_len": "1"
- },
- {
- "attr_name": "fan4_pwm",
- "attr_devtype": "cpld",
- "attr_devaddr": "0x32",
- "attr_offset": "0x15",
- "attr_mask": "0xff",
- "attr_len": "1"
- }
- ]
- }
- },
-
- "CONNECT_BOARD_CPLD2": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "CONNECT_BOARD_CPLD2",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x37",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "TEMP1": {
- "dev_info": {
- "device_type": "TEMP_SENSOR",
- "device_name": "MAC_TEMP_INLET",
- "device_parent": "SMBUS1"
- },
- "dev_attr": {
- "display_name": "Temp_1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x48",
- "dev_type": "lm75"
- },
- "attr_list": [{
- "attr_name": "temp1_high_threshold",
- "drv_attr_name": "temp1_max"
- },
- {
- "attr_name": "temp1_max_hyst"
- },
- {
- "attr_name": "temp1_input"
- }
- ]
- }
- },
-
- "TEMP2": {
- "dev_info": {
- "device_type": "TEMP_SENSOR",
- "device_name": "MAC_TEMP_OUTLET",
- "device_parent": "SMBUS1"
- },
- "dev_attr": {
- "display_name": "Temp_2"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x49",
- "dev_type": "lm75"
- },
- "attr_list": [{
- "attr_name": "temp1_high_threshold",
- "drv_attr_name": "temp1_max"
- },
- {
- "attr_name": "temp1_max_hyst"
- },
- {
- "attr_name": "temp1_input"
- }
- ]
- }
- },
-
- "TEMP3": {
- "dev_info": {
- "device_type": "TEMP_SENSOR",
- "device_name": "MAC_TEMP_HOTEST",
- "device_parent": "SMBUS1"
- },
- "dev_attr": {
- "display_name": "Temp_3"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x4a",
- "dev_type": "lm75"
- },
- "attr_list": [{
- "attr_name": "temp1_high_threshold",
- "drv_attr_name": "temp1_max"
- },
- {
- "attr_name": "temp1_max_hyst"
- },
- {
- "attr_name": "temp1_input"
- }
- ]
- }
- },
-
- "EEPROM1": {
- "dev_info": {
- "device_type": "EEPROM",
- "device_name": "EEPROM1",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x57",
- "dev_type": "24c02"
- },
- "dev_attr": {
- "access_mode": "BLOCK"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "MUX1": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "MUX1",
- "device_parent": "SMBUS1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2",
- "dev_addr": "0x70",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x3"
- },
- "channel": [{
- "chn": "0",
- "dev": "FAN1-EEPROM"
- },
- {
- "chn": "1",
- "dev": "FAN2-EEPROM"
- },
- {
- "chn": "2",
- "dev": "FAN3-EEPROM"
- },
- {
- "chn": "3",
- "dev": "FAN4-EEPROM"
- },
- {
- "chn": "4",
- "dev": "PSU1"
- },
- {
- "chn": "5",
- "dev": "PSU2"
- }
- ]
- }
- },
-
- "FAN1-EEPROM": {
- "dev_info": {
- "device_type": "EEPROM",
- "device_name": "FAN1-EEPROM",
- "device_parent": "MUX1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3",
- "dev_addr": "0x53",
- "dev_type": "rg_fan"
- },
- "dev_attr": {
- "access_mode": "BLOCK"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "FAN2-EEPROM": {
- "dev_info": {
- "device_type": "EEPROM",
- "device_name": "FAN2-EEPROM",
- "device_parent": "MUX1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x4",
- "dev_addr": "0x53",
- "dev_type": "rg_fan"
- },
- "dev_attr": {
- "access_mode": "BLOCK"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "FAN3-EEPROM": {
- "dev_info": {
- "device_type": "EEPROM",
- "device_name": "FAN3-EEPROM",
- "device_parent": "MUX1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x5",
- "dev_addr": "0x53",
- "dev_type": "rg_fan"
- },
- "dev_attr": {
- "access_mode": "BLOCK"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "FAN4-EEPROM": {
- "dev_info": {
- "device_type": "EEPROM",
- "device_name": "FAN4-EEPROM",
- "device_parent": "MUX1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x6",
- "dev_addr": "0x53",
- "dev_type": "rg_fan"
- },
- "dev_attr": {
- "access_mode": "BLOCK"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PSU1": {
- "dev_info": {
- "device_type": "PSU",
- "device_name": "PSU1",
- "device_parent": "MUX1"
- },
- "dev_attr": {
- "dev_idx": "1",
- "num_psu_fans": "1"
- },
- "i2c": {
- "interface": [{
- "itf": "pmbus",
- "dev": "PSU1-PMBUS"
- },
- {
- "itf": "eeprom",
- "dev": "PSU1-EEPROM"
- }
- ]
- }
- },
-
- "PSU1-PMBUS": {
- "dev_info": {
- "device_type": "PSU-PMBUS",
- "device_name": "PSU1-PMBUS",
- "device_parent": "MUX1",
- "virt_parent": "PSU1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x7",
- "dev_addr": "0x58",
- "dev_type": "psu_pmbus"
- },
- "attr_list": [{
- "attr_name": "psu_present",
- "attr_devaddr": "0x37",
- "attr_devtype": "cpld",
- "attr_offset": "0x51",
- "attr_mask": "0x1",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "psu_model_name",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x9a",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "12"
- },
- {
- "attr_name": "psu_power_good",
- "attr_devaddr": "0x37",
- "attr_devtype": "cpld",
- "attr_offset": "0x51",
- "attr_mask": "0x2",
- "attr_cmpval": "0x2",
- "attr_len": "1"
- },
- {
- "attr_name": "psu_mfr_id",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x99",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "10"
- },
- {
- "attr_name": "psu_fan_dir",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0xc3",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "5"
- },
- {
- "attr_name": "psu_v_out",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8b",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_i_out",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8c",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_p_out",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x96",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_fan1_speed_rpm",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x90",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_temp1_input",
- "attr_devaddr": "0x58",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8d",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- }
- ]
- }
- },
-
- "PSU1-EEPROM": {
- "dev_info": {
- "device_type": "PSU-EEPROM",
- "device_name": "PSU1-EEPROM",
- "device_parent": "MUX1",
- "virt_parent": "PSU1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x7",
- "dev_addr": "0x50",
- "dev_type": "psu_eeprom"
- },
- "attr_list": [{
- "attr_name": "psu_serial_num",
- "attr_devaddr": "0x50",
- "attr_devtype": "eeprom",
- "attr_offset": "0x38",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "20"
- }]
- }
- },
-
- "PSU2": {
- "dev_info": {
- "device_type": "PSU",
- "device_name": "PSU2",
- "device_parent": "MUX1"
- },
- "dev_attr": {
- "dev_idx": "2",
- "num_psu_fans": "1"
- },
- "i2c": {
- "interface": [{
- "itf": "pmbus",
- "dev": "PSU2-PMBUS"
- },
- {
- "itf": "eeprom",
- "dev": "PSU2-EEPROM"
- }
- ]
- }
- },
-
- "PSU2-PMBUS": {
- "dev_info": {
- "device_type": "PSU-PMBUS",
- "device_name": "PSU2-PMBUS",
- "device_parent": "MUX1",
- "virt_parent": "PSU2"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x8",
- "dev_addr": "0x5b",
- "dev_type": "psu_pmbus"
- },
- "attr_list": [{
- "attr_name": "psu_present",
- "attr_devaddr": "0x37",
- "attr_devtype": "cpld",
- "attr_offset": "0x51",
- "attr_mask": "0x10",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- },
- {
- "attr_name": "psu_model_name",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x9a",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "12"
- },
- {
- "attr_name": "psu_power_good",
- "attr_devaddr": "0x37",
- "attr_devtype": "cpld",
- "attr_offset": "0x51",
- "attr_mask": "0x20",
- "attr_cmpval": "0x20",
- "attr_len": "1"
- },
- {
- "attr_name": "psu_mfr_id",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x99",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "10"
- },
- {
- "attr_name": "psu_fan_dir",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0xc3",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "5"
- },
- {
- "attr_name": "psu_v_out",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8b",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_i_out",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8c",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_p_out",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x96",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_fan1_speed_rpm",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x90",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- },
- {
- "attr_name": "psu_temp1_input",
- "attr_devaddr": "0x5b",
- "attr_devtype": "pmbus",
- "attr_offset": "0x8d",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "2"
- }
- ]
- }
- },
-
- "PSU2-EEPROM": {
- "dev_info": {
- "device_type": "PSU-EEPROM",
- "device_name": "PSU2-EEPROM",
- "device_parent": "MUX1",
- "virt_parent": "PSU2"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x8",
- "dev_addr": "0x53",
- "dev_type": "psu_eeprom"
- },
- "attr_list": [{
- "attr_name": "psu_serial_num",
- "attr_devaddr": "0x53",
- "attr_devtype": "eeprom",
- "attr_offset": "0x38",
- "attr_mask": "0x0",
- "attr_cmpval": "0xff",
- "attr_len": "20"
- }]
- }
- },
-
- "I2C-GPIO0": {
- "dev_info": {
- "device_type": "I2C-GPIO",
- "device_name": "I2C-GPIO0",
- "device_parent": "SYSTEM"
- },
- "i2c": {
- "topo_info": {
- "dev_addr": "0x1"
- },
- "DEVICES": [{
- "dev": "MAC_BOARD_CPLD1_B"
- },
- {
- "dev": "MAC_BOARD_CPLD2_B"
- },
- {
- "dev": "PORT-MUX1"
- },
- {
- "dev": "PORT-MUX2"
- },
- {
- "dev": "PORT-MUX3"
- },
- {
- "dev": "PORT-MUX4"
- },
- {
- "dev": "PORT-MUX5"
- },
- {
- "dev": "PORT-MUX6"
- },
- {
- "dev": "PORT-MUX7"
- },
- {
- "dev": "PORT-MUX8"
- }
- ]
- }
- },
-
- "MAC_BOARD_CPLD1_B": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "MAC_BOARD_CPLD1_B",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x34",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "MAC_BOARD_CPLD2_B": {
- "dev_info": {
- "device_type": "CPLD",
- "device_name": "MAC_BOARD_CPLD2_B",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x36",
- "dev_type": "i2c_cpld"
- },
- "dev_attr": {}
- }
- },
-
- "PORT-MUX1": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX1",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x70",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0xb"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT1"
- },
- {
- "chn": "1",
- "dev": "PORT2"
- },
- {
- "chn": "2",
- "dev": "PORT3"
- },
- {
- "chn": "3",
- "dev": "PORT4"
- },
- {
- "chn": "4",
- "dev": "PORT5"
- },
- {
- "chn": "5",
- "dev": "PORT6"
- },
- {
- "chn": "6",
- "dev": "PORT7"
- },
- {
- "chn": "7",
- "dev": "PORT8"
- }
- ]
- }
- },
-
- "PORT-MUX2": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX2",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x71",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x13"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT9"
- },
- {
- "chn": "1",
- "dev": "PORT10"
- },
- {
- "chn": "2",
- "dev": "PORT11"
- },
- {
- "chn": "3",
- "dev": "PORT12"
- },
- {
- "chn": "4",
- "dev": "PORT13"
- },
- {
- "chn": "5",
- "dev": "PORT14"
- },
- {
- "chn": "6",
- "dev": "PORT15"
- },
- {
- "chn": "7",
- "dev": "PORT16"
- }
- ]
- }
- },
-
- "PORT-MUX3": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX3",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x72",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x1b"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT17"
- },
- {
- "chn": "1",
- "dev": "PORT18"
- },
- {
- "chn": "2",
- "dev": "PORT19"
- },
- {
- "chn": "3",
- "dev": "PORT20"
- },
- {
- "chn": "4",
- "dev": "PORT21"
- },
- {
- "chn": "5",
- "dev": "PORT22"
- },
- {
- "chn": "6",
- "dev": "PORT23"
- },
- {
- "chn": "7",
- "dev": "PORT24"
- }
- ]
- }
- },
-
- "PORT-MUX4": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX4",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x73",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x23"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT25"
- },
- {
- "chn": "1",
- "dev": "PORT26"
- },
- {
- "chn": "2",
- "dev": "PORT27"
- },
- {
- "chn": "3",
- "dev": "PORT28"
- },
- {
- "chn": "4",
- "dev": "PORT29"
- },
- {
- "chn": "5",
- "dev": "PORT30"
- },
- {
- "chn": "6",
- "dev": "PORT31"
- },
- {
- "chn": "7",
- "dev": "PORT32"
- }
- ]
- }
- },
-
- "PORT-MUX5": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX5",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x74",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x2b"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT33"
- },
- {
- "chn": "1",
- "dev": "PORT34"
- },
- {
- "chn": "2",
- "dev": "PORT35"
- },
- {
- "chn": "3",
- "dev": "PORT36"
- },
- {
- "chn": "4",
- "dev": "PORT37"
- },
- {
- "chn": "5",
- "dev": "PORT38"
- },
- {
- "chn": "6",
- "dev": "PORT39"
- },
- {
- "chn": "7",
- "dev": "PORT40"
- }
- ]
- }
- },
-
- "PORT-MUX6": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX6",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x75",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x33"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT41"
- },
- {
- "chn": "1",
- "dev": "PORT42"
- },
- {
- "chn": "2",
- "dev": "PORT43"
- },
- {
- "chn": "3",
- "dev": "PORT44"
- },
- {
- "chn": "4",
- "dev": "PORT45"
- },
- {
- "chn": "5",
- "dev": "PORT46"
- },
- {
- "chn": "6",
- "dev": "PORT47"
- },
- {
- "chn": "7",
- "dev": "PORT48"
- }
- ]
- }
- },
-
- "PORT-MUX7": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX7",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x76",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x3b"
- },
- "channel": [{
- "chn": "0",
- "dev": "PORT49"
- },
- {
- "chn": "1",
- "dev": "PORT50"
- },
- {
- "chn": "2",
- "dev": "PORT51"
- },
- {
- "chn": "3",
- "dev": "PORT52"
- },
- {
- "chn": "4",
- "dev": "PORT53"
- },
- {
- "chn": "5",
- "dev": "PORT54"
- },
- {
- "chn": "6",
- "dev": "PORT55"
- },
- {
- "chn": "7",
- "dev": "PORT56"
- }
- ]
- }
- },
-
- "PORT-MUX8": {
- "dev_info": {
- "device_type": "MUX",
- "device_name": "PORT-MUX8",
- "device_parent": "I2C-GPIO0"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1",
- "dev_addr": "0x77",
- "dev_type": "pca9548"
- },
- "dev_attr": {
- "virt_bus": "0x43"
- },
- "channel": []
- }
- },
-
- "PORT1": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT1",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "1"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT1-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT1-CTRL"
- }]
- }
- },
-
- "PORT1-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT1-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xb",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT1-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT1-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT1"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xb",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT2": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT2",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "2"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT2-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT2-CTRL"
- }]
- }
- },
-
- "PORT2-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT2-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT2"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xc",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT2-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT2-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT2"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xc",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT3": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT3",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "3"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT3-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT3-CTRL"
- }]
- }
- },
-
- "PORT3-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT3-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT3"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xd",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT3-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT3-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT3"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xd",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT4": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT4",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "4"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT4-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT4-CTRL"
- }]
- }
- },
-
- "PORT4-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT4-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT4"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xe",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT4-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT4-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT4"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xe",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT5": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT5",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "5"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT5-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT5-CTRL"
- }]
- }
- },
-
- "PORT5-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT5-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT5"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xf",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT5-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT5-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT5"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0xf",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT6": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT6",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "6"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT6-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT6-CTRL"
- }]
- }
- },
-
- "PORT6-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT6-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT6"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x10",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT6-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT6-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT6"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x10",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT7": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT7",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "7"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT7-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT7-CTRL"
- }]
- }
- },
-
- "PORT7-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT7-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT7"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x11",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT7-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT7-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT7"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x11",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT8": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT8",
- "device_parent": "PORT-MUX1"
- },
- "dev_attr": {
- "dev_idx": "8"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT8-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT8-CTRL"
- }]
- }
- },
-
- "PORT8-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT8-EEPROM",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT8"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x12",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT8-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT8-CTRL",
- "device_parent": "PORT-MUX1",
- "virt_parent": "PORT8"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x12",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT9": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT9",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "9"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT9-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT9-CTRL"
- }]
- }
- },
-
- "PORT9-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT9-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT9"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x13",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT9-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT9-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT9"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x13",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT10": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT10",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "10"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT10-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT10-CTRL"
- }]
- }
- },
-
- "PORT10-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT10-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT10"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x14",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT10-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT10-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT10"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x14",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT11": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT11",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "11"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT11-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT11-CTRL"
- }]
- }
- },
-
- "PORT11-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT11-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT11"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x15",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT11-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT11-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT11"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x15",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT12": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT12",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "12"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT12-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT12-CTRL"
- }]
- }
- },
-
- "PORT12-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT12-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT12"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x16",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT12-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT12-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT12"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x16",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT13": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT13",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "13"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT13-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT13-CTRL"
- }]
- }
- },
-
- "PORT13-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT13-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT13"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x17",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT13-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT13-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT13"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x17",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT14": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT14",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "14"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT14-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT14-CTRL"
- }]
- }
- },
-
- "PORT14-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT14-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT14"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x18",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT14-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT14-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT14"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x18",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT15": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT15",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "15"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT15-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT15-CTRL"
- }]
- }
- },
-
- "PORT15-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT15-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT15"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x19",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT15-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT15-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT15"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x19",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT16": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT16",
- "device_parent": "PORT-MUX2"
- },
- "dev_attr": {
- "dev_idx": "16"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT16-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT16-CTRL"
- }]
- }
- },
-
- "PORT16-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT16-EEPROM",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT16"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1a",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT16-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT16-CTRL",
- "device_parent": "PORT-MUX2",
- "virt_parent": "PORT16"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1a",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT17": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT17",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "17"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT17-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT17-CTRL"
- }]
- }
- },
-
- "PORT17-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT17-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT17"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1b",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT17-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT17-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT17"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1b",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT18": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT18",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "18"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT18-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT18-CTRL"
- }]
- }
- },
-
- "PORT18-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT18-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT18"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1c",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT18-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT18-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT18"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1c",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT19": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT19",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "19"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT19-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT19-CTRL"
- }]
- }
- },
-
- "PORT19-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT19-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT19"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1d",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT19-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT19-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT19"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1d",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT20": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT20",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "20"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT20-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT20-CTRL"
- }]
- }
- },
-
- "PORT20-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT20-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT20"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1e",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT20-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT20-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT20"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1e",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT21": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT21",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "21"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT21-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT21-CTRL"
- }]
- }
- },
-
- "PORT21-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT21-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT21"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1f",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT21-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT21-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT21"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x1f",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT22": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT22",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "22"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT22-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT22-CTRL"
- }]
- }
- },
-
- "PORT22-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT22-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT22"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x20",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT22-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT22-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT22"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x20",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT23": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT23",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "23"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT23-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT23-CTRL"
- }]
- }
- },
-
- "PORT23-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT23-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT23"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x21",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT23-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT23-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT23"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x21",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT24": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT24",
- "device_parent": "PORT-MUX3"
- },
- "dev_attr": {
- "dev_idx": "24"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT24-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT24-CTRL"
- }]
- }
- },
-
- "PORT24-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT24-EEPROM",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT24"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x22",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT24-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT24-CTRL",
- "device_parent": "PORT-MUX3",
- "virt_parent": "PORT24"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x22",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD1_B",
- "attr_devaddr": "0x34",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT25": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT25",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "25"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT25-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT25-CTRL"
- }]
- }
- },
-
- "PORT25-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT25-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT25"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x23",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT25-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT25-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT25"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x23",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT26": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT26",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "26"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT26-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT26-CTRL"
- }]
- }
- },
-
- "PORT26-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT26-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT26"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x24",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT26-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT26-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT26"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x24",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT27": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT27",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "27"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT27-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT27-CTRL"
- }]
- }
- },
-
- "PORT27-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT27-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT27"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x25",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT27-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT27-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT27"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x25",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT28": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT28",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "28"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT28-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT28-CTRL"
- }]
- }
- },
-
- "PORT28-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT28-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT28"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x26",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT28-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT28-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT28"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x26",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT29": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT29",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "29"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT29-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT29-CTRL"
- }]
- }
- },
-
- "PORT29-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT29-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT29"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x27",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT29-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT29-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT29"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x27",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT30": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT30",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "30"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT30-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT30-CTRL"
- }]
- }
- },
-
- "PORT30-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT30-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT30"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x28",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT30-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT30-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT30"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x28",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT31": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT31",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "31"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT31-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT31-CTRL"
- }]
- }
- },
-
- "PORT31-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT31-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT31"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x29",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT31-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT31-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT31"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x29",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT32": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT32",
- "device_parent": "PORT-MUX4"
- },
- "dev_attr": {
- "dev_idx": "32"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT32-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT32-CTRL"
- }]
- }
- },
-
- "PORT32-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT32-EEPROM",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT32"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2a",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT32-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT32-CTRL",
- "device_parent": "PORT-MUX4",
- "virt_parent": "PORT32"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2a",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x30",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x60",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x40",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT33": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT33",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "33"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT33-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT33-CTRL"
- }]
- }
- },
-
- "PORT33-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT33-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT33"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2b",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT33-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT33-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT33"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2b",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT34": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT34",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "34"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT34-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT34-CTRL"
- }]
- }
- },
-
- "PORT34-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT34-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT34"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2c",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT34-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT34-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT34"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2c",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT35": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT35",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "35"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT35-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT35-CTRL"
- }]
- }
- },
-
- "PORT35-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT35-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT35"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2d",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT35-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT35-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT35"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2d",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT36": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT36",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "36"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT36-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT36-CTRL"
- }]
- }
- },
-
- "PORT36-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT36-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT36"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2e",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT36-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT36-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT36"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2e",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT37": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT37",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "37"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT37-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT37-CTRL"
- }]
- }
- },
-
- "PORT37-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT37-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT37"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2f",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT37-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT37-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT37"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x2f",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT38": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT38",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "38"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT38-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT38-CTRL"
- }]
- }
- },
-
- "PORT38-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT38-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT38"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x30",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT38-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT38-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT38"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x30",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT39": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT39",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "39"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT39-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT39-CTRL"
- }]
- }
- },
-
- "PORT39-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT39-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT39"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x31",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT39-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT39-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT39"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x31",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT40": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT40",
- "device_parent": "PORT-MUX5"
- },
- "dev_attr": {
- "dev_idx": "40"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT40-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT40-CTRL"
- }]
- }
- },
-
- "PORT40-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT40-EEPROM",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT40"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x32",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT40-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT40-CTRL",
- "device_parent": "PORT-MUX5",
- "virt_parent": "PORT40"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x32",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x31",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x61",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x41",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT41": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT41",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "41"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT41-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT41-CTRL"
- }]
- }
- },
-
- "PORT41-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT41-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT41"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x33",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT41-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT41-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT41"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x33",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT42": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT42",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "42"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT42-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT42-CTRL"
- }]
- }
- },
-
- "PORT42-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT42-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT42"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x34",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT42-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT42-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT42"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x34",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT43": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT43",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "43"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT43-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT43-CTRL"
- }]
- }
- },
-
- "PORT43-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT43-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT43"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x35",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT43-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT43-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT43"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x35",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT44": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT44",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "44"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT44-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT44-CTRL"
- }]
- }
- },
-
- "PORT44-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT44-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT44"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x36",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT44-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT44-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT44"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x36",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT45": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT45",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "45"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT45-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT45-CTRL"
- }]
- }
- },
-
- "PORT45-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT45-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT45"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x37",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT45-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT45-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT45"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x37",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT46": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT46",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "46"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT46-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT46-CTRL"
- }]
- }
- },
-
- "PORT46-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT46-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT46"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x38",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT46-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT46-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT46"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x38",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT47": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT47",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "47"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT47-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT47-CTRL"
- }]
- }
- },
-
- "PORT47-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT47-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT47"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x39",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT47-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT47-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT47"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x39",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT48": {
- "dev_info": {
- "device_type": "SFP28",
- "device_name": "PORT48",
- "device_parent": "PORT-MUX6"
- },
- "dev_attr": {
- "dev_idx": "48"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT48-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT48-CTRL"
- }]
- }
- },
-
- "PORT48-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT48-EEPROM",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT48"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3a",
- "dev_addr": "0x50",
- "dev_type": "optoe2"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT48-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT48-CTRL",
- "device_parent": "PORT-MUX6",
- "virt_parent": "PORT48"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3a",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x32",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_txdisable",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x62",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_intr_status",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x42",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT49": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT49",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "49"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT49-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT49-CTRL"
- }]
- }
- },
-
- "PORT49-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT49-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT49"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3b",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT49-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT49-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT49"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3b",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x00",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT50": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT50",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "50"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT50-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT50-CTRL"
- }]
- }
- },
-
- "PORT50-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT50-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT50"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3c",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT50-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT50-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT50"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3c",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x01",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT51": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT51",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "51"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT51-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT51-CTRL"
- }]
- }
- },
-
- "PORT51-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT51-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT51"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3d",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT51-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT51-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT51"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3d",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x02",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT52": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT52",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "52"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT52-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT52-CTRL"
- }]
- }
- },
-
- "PORT52-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT52-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT52"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3e",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT52-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT52-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT52"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3e",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x03",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT53": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT53",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "53"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT53-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT53-CTRL"
- }]
- }
- },
-
- "PORT53-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT53-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT53"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3f",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT53-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT53-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT53"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x3f",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x04",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
-
- "PORT54": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT54",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "54"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT54-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT54-CTRL"
- }]
- }
- },
-
- "PORT54-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT54-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT54"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x40",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT54-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT54-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT54"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x40",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x05",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT55": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT55",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "55"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT55-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT55-CTRL"
- }]
- }
- },
-
- "PORT55-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT55-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT55"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x41",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT55-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT55-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT55"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x41",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x06",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "PORT56": {
- "dev_info": {
- "device_type": "QSFP28",
- "device_name": "PORT56",
- "device_parent": "PORT-MUX7"
- },
- "dev_attr": {
- "dev_idx": "56"
- },
- "i2c": {
- "interface": [{
- "itf": "eeprom",
- "dev": "PORT56-EEPROM"
- }, {
- "itf": "control",
- "dev": "PORT56-CTRL"
- }]
- }
- },
-
- "PORT56-EEPROM": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT56-EEPROM",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT56"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x42",
- "dev_addr": "0x50",
- "dev_type": "optoe1"
- },
- "attr_list": [{
- "attr_name": "eeprom"
- }]
- }
- },
-
- "PORT56-CTRL": {
- "dev_info": {
- "device_type": "",
- "device_name": "PORT56-CTRL",
- "device_parent": "PORT-MUX7",
- "virt_parent": "PORT56"
- },
- "i2c": {
- "topo_info": {
- "parent_bus": "0x42",
- "dev_addr": "0x53",
- "dev_type": "pddf_xcvr"
- },
- "attr_list": [{
- "attr_name": "xcvr_present",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devaddr": "0x36",
- "attr_devtype": "cpld",
- "attr_offset": "0x33",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }, {
- "attr_name": "xcvr_reset",
- "attr_devaddr": "0x36",
- "attr_devname": "MAC_BOARD_CPLD2_B",
- "attr_devtype": "cpld",
- "attr_offset": "0xb9",
- "attr_mask": "0x07",
- "attr_cmpval": "0x0",
- "attr_len": "1"
- }]
- }
- },
-
- "FRONT_BOARD_BMC_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "DIAG_LED"
- },
- "dev_attr": {
- "index": "0"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "2:0",
- "value": "0x2",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "2:0",
- "value": "0x1",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "2:0",
- "value": "0x4",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "2:0",
- "value": "0x3",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "2:0",
- "value": "0x6",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "2:0",
- "value": "0x5",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "2:0",
- "value": "0x0",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb1"
- }
- ]
- }
- },
-
- "FRONT_BOARD_CPU_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "SYS_LED"
- },
- "dev_attr": {
- "index": "0"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "2:0",
- "value": "0x2",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "2:0",
- "value": "0x1",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "2:0",
- "value": "0x4",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "2:0",
- "value": "0x3",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "2:0",
- "value": "0x6",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "2:0",
- "value": "0x5",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "2:0",
- "value": "0x0",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb2"
- }
- ]
- }
- },
-
- "FRONT_BOARD_PSU_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "LOC_LED"
- },
- "dev_attr": {
- "index": "0"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "2:0",
- "value": "0x2",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "2:0",
- "value": "0x1",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "2:0",
- "value": "0x4",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "2:0",
- "value": "0x3",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "2:0",
- "value": "0x6",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "2:0",
- "value": "0x5",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "2:0",
- "value": "0x0",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb3"
- }
- ]
- }
- },
-
- "FRONT_BOARD_FAN_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "FAN_LED"
- },
- "dev_attr": {
- "index": "0"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "2:0",
- "value": "0x2",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "2:0",
- "value": "0x1",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "2:0",
- "value": "0x4",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "2:0",
- "value": "0x3",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "2:0",
- "value": "0x6",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "2:0",
- "value": "0x5",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "2:0",
- "value": "0x0",
- "swpld_addr": "0x33",
- "swpld_addr_offset": "0xb4"
- }
- ]
- }
- },
-
- "FAN1_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "FANTRAY_LED"
- },
- "dev_attr": {
- "index": "0"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "3:0",
- "value": "0xa",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "3:0",
- "value": "0xe",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "3:0",
- "value": "0x9",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "3:0",
- "value": "0xd",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "3:0",
- "value": "0x3",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "3:0",
- "value": "0x7",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "3:0",
- "value": "0xb",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x23"
- }
- ]
- }
- },
-
- "FAN2_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "FANTRAY_LED"
- },
- "dev_attr": {
- "index": "1"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "3:0",
- "value": "0xa",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "3:0",
- "value": "0xe",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "3:0",
- "value": "0x9",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "3:0",
- "value": "0xd",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "3:0",
- "value": "0x3",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "3:0",
- "value": "0x7",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "3:0",
- "value": "0xb",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x24"
- }
- ]
- }
- },
-
- "FAN3_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "FANTRAY_LED"
- },
- "dev_attr": {
- "index": "2"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "3:0",
- "value": "0xa",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "3:0",
- "value": "0xe",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "3:0",
- "value": "0x9",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "3:0",
- "value": "0xd",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "3:0",
- "value": "0x3",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "3:0",
- "value": "0x7",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "3:0",
- "value": "0xb",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x25"
- }
- ]
- }
- },
-
- "FAN4_LED": {
- "dev_info": {
- "device_type": "LED",
- "device_name": "FANTRAY_LED"
- },
- "dev_attr": {
- "index": "3"
- },
- "i2c": {
- "attr_list": [{
- "attr_name": "STATUS_LED_COLOR_RED",
- "descr": "Red",
- "bits": "3:0",
- "value": "0xa",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_RED_BLINK",
- "descr": "Red Blinking",
- "bits": "3:0",
- "value": "0xe",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN",
- "descr": "Green",
- "bits": "3:0",
- "value": "0x9",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_GREEN_BLINK",
- "descr": "Green Blinking",
- "bits": "3:0",
- "value": "0xd",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER",
- "descr": "Amber",
- "bits": "3:0",
- "value": "0x3",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_AMBER_BLINK",
- "descr": "Amber Blinking",
- "bits": "3:0",
- "value": "0x7",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- },
- {
- "attr_name": "STATUS_LED_COLOR_OFF",
- "descr": "Off",
- "bits": "3:0",
- "value": "0xb",
- "swpld_addr": "0x32",
- "swpld_addr_offset": "0x26"
- }
- ]
- }
- }
-}
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform.json
new file mode 100644
index 0000000000..6e9b40b805
--- /dev/null
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform.json
@@ -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": {}
+}
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform_components.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform_components.json
new file mode 100644
index 0000000000..2e6f4b8d12
--- /dev/null
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/platform_components.json
@@ -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)"
+ }
+ }
+ }
+ }
+}
+
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/eeprom.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/eeprom.py
deleted file mode 100755
index cf7215e0c9..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/eeprom.py
+++ /dev/null
@@ -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)
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/fanutil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/fanutil.py
deleted file mode 100755
index 58c38d1d73..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/fanutil.py
+++ /dev/null
@@ -1,187 +0,0 @@
-# Sample pddf_fanutil file
-# All the supported FAN SysFS aattributes are
-#- fan_present
-#- fan_direction
-#- fan_input
-#- fan_pwm
-#- fan_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
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ledutil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ledutil.py
deleted file mode 100755
index 5f9e2e99db..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ledutil.py
+++ /dev/null
@@ -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)
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/psuutil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/psuutil.py
deleted file mode 100755
index dccb1ac1a1..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/psuutil.py
+++ /dev/null
@@ -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')
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sfputil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sfputil.py
old mode 100755
new mode 100644
index 1ca9256108..3e195a36f6
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sfputil.py
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sfputil.py
@@ -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
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ssd_util.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ssd_util.py
new file mode 100755
index 0000000000..89d3ccd770
--- /dev/null
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/ssd_util.py
@@ -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
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sysstatutil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sysstatutil.py
deleted file mode 100755
index af4dd59153..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/sysstatutil.py
+++ /dev/null
@@ -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')
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/thermalutil.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/thermalutil.py
deleted file mode 100755
index 6aef47b7e9..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/plugins/thermalutil.py
+++ /dev/null
@@ -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')
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pmon_daemon_control.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pmon_daemon_control.json
index 50c21289d2..94592fa8ce 100644
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pmon_daemon_control.json
+++ b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pmon_daemon_control.json
@@ -1,3 +1,3 @@
-{
- "skip_ledd": true
-}
+{
+ "skip_ledd": true
+}
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sensors.conf b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sensors.conf
deleted file mode 100755
index 9b0569d154..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sensors.conf
+++ /dev/null
@@ -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
-
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/chassis.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/chassis.json
deleted file mode 100644
index c5ea46918f..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/chassis.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "eeprom": {"bus": 2, "loc": "0057"}
-}
\ No newline at end of file
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/component.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/component.json
deleted file mode 100644
index 35f4b45864..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/component.json
+++ /dev/null
@@ -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
- }
- ]
-}
\ No newline at end of file
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/fan.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/fan.json
deleted file mode 100644
index de7030ec1f..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/fan.json
+++ /dev/null
@@ -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
- }
- ]
- }
- ]
-}
\ No newline at end of file
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/psu.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/psu.json
deleted file mode 100644
index c807b51fc4..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/psu.json
+++ /dev/null
@@ -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
- }
- }
- ]
-}
\ No newline at end of file
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/thermal.json b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/thermal.json
deleted file mode 100644
index 3193366735..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/sonic_platform_config/thermal.json
+++ /dev/null
@@ -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
- }
- }
- ]
-}
\ No newline at end of file
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf_support b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/system_health_monitoring_config.json
old mode 100644
new mode 100755
similarity index 100%
rename from device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/pddf_support
rename to device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/system_health_monitoring_config.json
diff --git a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/systest.py b/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/systest.py
deleted file mode 100644
index 38e9ff6aa0..0000000000
--- a/device/ragile/x86_64-ragile_ra-b6510-48v8c-r0/systest.py
+++ /dev/null
@@ -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)
diff --git a/platform/broadcom/one-image.mk b/platform/broadcom/one-image.mk
index 82c96104a0..d4289fd4e2 100755
--- a/platform/broadcom/one-image.mk
+++ b/platform/broadcom/one-image.mk
@@ -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) \
diff --git a/platform/broadcom/platform-modules-ragile.mk b/platform/broadcom/platform-modules-ragile.mk
index 12236b1e72..b0cc3b91b2 100644
--- a/platform/broadcom/platform-modules-ragile.mk
+++ b/platform/broadcom/platform-modules-ragile.mk
@@ -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)))
diff --git a/platform/broadcom/sonic-platform-modules-ragile/LICENSE b/platform/broadcom/sonic-platform-modules-ragile/LICENSE
old mode 100755
new mode 100644
index d37122689f..5681cac344
--- a/platform/broadcom/sonic-platform-modules-ragile/LICENSE
+++ b/platform/broadcom/sonic-platform-modules-ragile/LICENSE
@@ -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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/Makefile
index 6daf3d2b2f..578d65b3bf 100755
--- a/platform/broadcom/sonic-platform-modules-ragile/common/Makefile
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/Makefile
new file mode 100644
index 0000000000..25ba3c5a91
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/Makefile
new file mode 100644
index 0000000000..e4078716eb
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/Makefile
@@ -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)/*
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_debug.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_debug.c
new file mode 100644
index 0000000000..93ed6066ef
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_debug.c
@@ -0,0 +1,43 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.c
new file mode 100644
index 0000000000..9c71183095
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.c
@@ -0,0 +1,1802 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "dfd_utest.h"
+
+#define DFD_UTEST_MAX_RDWR_NUM (256)
+#define DFD_UTEST_DEFAULT_WR_NUM (1)
+
+#define DEV_MEM_NAME "/dev/mem"
+#define DEV_KMEM_NAME "/dev/kmem"
+
+#define WIDTH_1Byte (1)
+#define WIDTH_2Byte (2)
+#define WIDTH_4Byte (4)
+#define DFD_UTEST_MAX_BIT_WIDTH (4)
+
+#ifdef DFD_UTEST_ITEM
+#undef DFD_UTEST_ITEM
+#endif
+#define DFD_UTEST_ITEM(_id, _type_str, _help_info, _help_info_detail) {_id, #_type_str, dfd_utest_##_type_str, _help_info, _help_info_detail},
+static dfd_utest_t g_dfd_unit_test[] = {
+ DFD_UTEST_ITEM_ALL
+};
+
+static int g_sys_page_size;
+#define SYS_PAGE_SIZE g_sys_page_size
+#define SYS_PAGE_MASK (~(SYS_PAGE_SIZE - 1))
+
+void dfd_utest_print_cmd(int argc, char* argv[])
+{
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ if (i != 1) {
+ printf(" ");
+ }
+ printf("%s", argv[i]);
+ }
+ return;
+}
+
+void dfd_utest_print_all_help(void)
+{
+ int i, tbl_size;
+
+ tbl_size = sizeof(g_dfd_unit_test) / sizeof(g_dfd_unit_test[0]);
+
+ for (i = 0; i < tbl_size; i++) {
+ printf("%-20s\t\t\t%s\r\n", g_dfd_unit_test[i].type_str, g_dfd_unit_test[i].help_info);
+ }
+
+ return;
+}
+
+void dfd_utest_printf_single_help(int utest_type)
+{
+ int i, tbl_size;
+
+ tbl_size = sizeof(g_dfd_unit_test) / sizeof(g_dfd_unit_test[0]);
+ for (i = 0; i < tbl_size; i++) {
+ if (g_dfd_unit_test[i].utest_type == utest_type) {
+ printf("%-20s\t\t\t%s\r\n", g_dfd_unit_test[i].type_str, g_dfd_unit_test[i].help_info_detail);
+ return;
+ }
+ }
+
+ DFD_DEBUG_DBG("type: %d not match.\n", utest_type);
+ return;
+
+}
+
+void dfd_utest_printf_reg(uint8_t *buf, int buf_len, uint32_t offset_addr)
+{
+ int i, j, tmp;
+
+ j = offset_addr % 16;
+ tmp = j;
+ offset_addr -= j;
+ printf("\n ");
+
+ for (i = 0; i < 16; i++) {
+ printf("%2x ", i);
+ }
+
+ for (i = 0; i < buf_len + j; i++) {
+ if ((i % 16) == 0) {
+ printf("\n0x%08x ", offset_addr);
+ offset_addr = offset_addr + 16;
+ }
+ if (tmp) {
+ printf(" ");
+ tmp--;
+ } else {
+ printf("%02x ", buf[i-j]);
+ }
+ }
+
+ printf("\n");
+ return;
+}
+
+#define I2C_RETRIES 0x0701
+#define I2C_TIMEOUT 0x0702
+#define I2C_RDWR 0x0707
+
+#define I2C_SLAVE 0x0703 /* Use this slave address */
+
+#define I2C_SLAVE_FORCE 0x0706 /* Use this slave address, even if it
+ is already in use by a driver! */
+#define I2C_PEC 0x0708 /* != 0 to use PEC with SMBus */
+#define I2C_SMBUS 0x0720 /* SMBus transfer */
+
+struct i2c_msg
+{
+ unsigned short addr;
+ unsigned short flags;
+#define I2C_M_TEN 0x0010
+#define I2C_M_RD 0x0001
+ unsigned short len;
+ unsigned char *buf;
+};
+
+struct i2c_rdwr_ioctl_data
+{
+ struct i2c_msg *msgs;
+ int nmsgs;
+
+};
+
+#define DFD_I2C_SHORT_ADDR_TYPE 0
+#define DFD_I2C_RETRY_SLEEP_TIME (10000) /* 10ms */
+#define DFD_I2C_RETRY_TIME (50000 / DFD_I2C_RETRY_SLEEP_TIME)
+/* i2c_smbus_xfer read or write markers */
+#define I2C_SMBUS_READ 1
+#define I2C_SMBUS_WRITE 0
+
+/* SMBus transaction types (size parameter in the above functions)
+ Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
+#define I2C_SMBUS_QUICK 0
+#define I2C_SMBUS_BYTE 1
+#define I2C_SMBUS_BYTE_DATA 2
+#define I2C_SMBUS_WORD_DATA 3
+#define I2C_SMBUS_PROC_CALL 4
+#define I2C_SMBUS_BLOCK_DATA 5
+#define I2C_SMBUS_I2C_BLOCK_BROKEN 6
+#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
+#define I2C_SMBUS_I2C_BLOCK_DATA 8
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,36)
+/* fix tjm */
+
+#ifndef __ASSEMBLY__
+/*
+ * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
+ * header files exported to user space
+ */
+typedef __signed__ char __s8;
+typedef unsigned char __u8;
+
+typedef __signed__ short __s16;
+typedef unsigned short __u16;
+
+typedef __signed__ int __s32;
+typedef unsigned int __u32;
+
+typedef __signed__ long __s64;
+typedef unsigned long __u64;
+
+#endif /* __ASSEMBLY__ */
+
+#else
+/* do noting add tjm */
+#endif
+
+/*
+ * Data for SMBus Messages
+ */
+#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
+union i2c_smbus_data {
+ __u8 byte;
+ __u16 word;
+ __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
+ /* and one more for user-space compatibility */
+};
+
+/* This is the structure as used in the I2C_SMBUS ioctl call */
+struct i2c_smbus_ioctl_data {
+ __u8 read_write;
+ __u8 command;
+ __u32 size;
+ union i2c_smbus_data *data;
+};
+int32_t dfd_read_port_i2c_one_time_smbus(char *i2c_name, uint16_t dev_addr, uint16_t offset_addr,
+ uint8_t *recv_buf, int32_t size, int addr_type)
+{
+ union i2c_smbus_data data;
+ struct i2c_smbus_ioctl_data ioctl_data;
+ unsigned long addr = dev_addr;
+ int fd;
+ int rc;
+ int rv;
+ int i;
+
+ mem_clear(&ioctl_data, sizeof(struct i2c_smbus_ioctl_data));
+ if (i2c_name == NULL || recv_buf == NULL) {
+ DFD_DEBUG_ERROR("i2c_num = NULL, recv_buf = NULL\r\n");
+ return -1;
+ }
+
+ DFD_DEBUG_DBG("i2c name: %s, dev_addr: 0x%x, offset_addr: 0x%x, size: %d, addr_type: %d.\n", i2c_name, dev_addr,
+ offset_addr, size, addr_type);
+
+ rv = 0;
+ fd = open(i2c_name, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ DFD_DEBUG_ERROR("i2c open fail fd %d\n", fd);
+ rv = fd;
+ goto err;
+ }
+ if (ioctl(fd, I2C_SLAVE_FORCE , addr) < 0) {
+ DFD_DEBUG_ERROR("ioctl 2C_SLAVE_FORCE %d.\n", errno);
+ rv =-1;
+ goto fail;
+ }
+ for (i = 0 ;i < size; i++) {
+ data.byte = 0;
+ ioctl_data.read_write = I2C_SMBUS_READ;
+ ioctl_data.command = (offset_addr + i);
+ ioctl_data.size = I2C_SMBUS_BYTE_DATA;
+ ioctl_data.data= &data;
+
+ rc = ioctl(fd, I2C_SMBUS, &ioctl_data);
+ if (rc < 0) {
+ DFD_DEBUG_ERROR("read, I2C_SMBUS failed: %d.\n", errno);
+ rv = -1;
+ goto fail;
+ }
+ *(recv_buf + i) = data.byte;
+ }
+ fail:
+ close(fd);
+ err:
+ return rv;
+
+}
+
+int32_t dfd_read_port_i2c_one_time(char *i2c_name, uint16_t dev_addr, uint16_t offset_addr,
+ uint8_t *recv_buf, int32_t size, int addr_type)
+{
+
+ int32_t fd, rv;
+ struct i2c_rdwr_ioctl_data ioctl_data;
+ struct i2c_msg msgs[2];
+ uint8_t buf[2];
+
+ if (i2c_name == NULL || recv_buf == NULL) {
+ DFD_DEBUG_ERROR("i2c_num = NULL, recv_buf = NULL\r\n");
+ return -1;
+ }
+
+ DFD_DEBUG_DBG("i2c name %s, dev_addr 0x%x, offset_addr 0x%x, size %d, addr_type %d.\n", i2c_name, dev_addr,
+ offset_addr, size, addr_type);
+
+ rv = 0;
+ fd = open(i2c_name, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ DFD_DEBUG_ERROR("i2c open fail fd %d\n", fd);
+ return -1;
+ }
+ mem_clear(&ioctl_data, sizeof(ioctl_data));
+ mem_clear(msgs, sizeof(msgs));
+ mem_clear(buf, sizeof(buf));
+ if (ioctl(fd, I2C_SLAVE, dev_addr) < 0) {
+
+ DFD_DEBUG_ERROR("%s %dioctl fail(ret:%d, errno:%s)!\r\n", __func__ , __LINE__, rv, strerror(errno));
+ rv = -1;
+ goto fail;
+ }
+
+ buf[0] = (uint8_t)(offset_addr);
+ msgs[0].addr= dev_addr;
+ msgs[0].len= 2;
+ msgs[0].buf= buf;
+ msgs[1].addr= dev_addr;
+ msgs[1].flags|= I2C_M_RD;
+ msgs[1].len= 1;
+ msgs[1].buf= recv_buf;
+ ioctl_data.nmsgs= 1;
+ ioctl_data.msgs= msgs;
+
+ rv = ioctl(fd, I2C_RDWR, &ioctl_data);
+ if(rv < 0) {
+ DFD_DEBUG_ERROR("%s %dioctl fail(ret:%d, errno:%s)!\r\n", __func__ , __LINE__, rv, strerror(errno));
+ goto fail;
+ }
+ ioctl_data.msgs= &msgs[1];
+ DFD_DEBUG_DBG("ioctlread, return :%d/n", ioctl(fd, I2C_RDWR, &ioctl_data));
+ DFD_DEBUG_DBG("dfd_read_port_i2c addr: 0x%X, offset: 0x%X, value: 0x%X\n", dev_addr, offset_addr, *recv_buf);
+ fail:
+ close(fd);
+ return rv;
+
+}
+
+int32_t dfd_read_port_i2c(char *i2c_name, uint16_t dev_addr, uint16_t offset_addr,
+ uint8_t *recv_buf, int32_t size)
+{
+ int i;
+ int rv;
+
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ rv = dfd_read_port_i2c_one_time_smbus(i2c_name, dev_addr, offset_addr, recv_buf, size, DFD_I2C_SHORT_ADDR_TYPE);
+ if (rv < 0) {
+ DFD_DEBUG_ERROR("(read times %d)i2c name %s, dev_addr 0x%X, offset_addr 0x%X, addr_type %d\n", i, i2c_name, dev_addr, offset_addr, DFD_I2C_SHORT_ADDR_TYPE);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+
+ return rv;
+}
+
+int32_t dfd_write_port_i2c_one_time(char *i2c_name, uint16_t dev_addr, uint16_t offset_addr,
+ uint8_t *write_buf, int32_t size,int addr_type)
+{
+ int32_t fd, rv;
+ int index;
+ struct i2c_smbus_ioctl_data ioctl_data;
+ union i2c_smbus_data data;
+ uint8_t addr_buf[2];
+ uint8_t write_buf_tmp[256];
+
+ if (i2c_name == NULL || write_buf == NULL ) {
+ DFD_DEBUG_ERROR("i2c_num = NULL \r\n");
+ return -1;
+ }
+
+ if (size <= 0) {
+ DFD_DEBUG_ERROR("error:size\n");
+ return -1;
+ }
+ DFD_DEBUG_DBG("i2c name %s, dev_addr 0x%x, offset_addr 0x%x, size %d, addr_type %d\n",i2c_name, dev_addr,
+ offset_addr, size, addr_type);
+ mem_clear(&ioctl_data, sizeof(ioctl_data));
+ mem_clear(addr_buf, sizeof(addr_buf));
+ mem_clear(write_buf_tmp, sizeof(write_buf_tmp));
+
+ rv = 0;
+
+ fd = open(i2c_name, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ DFD_DEBUG_ERROR("i2c open fail fd %d\n", fd);
+ return -1;
+ }
+
+ if (ioctl(fd, I2C_SLAVE_FORCE, dev_addr) < 0) {
+ DFD_DEBUG_ERROR("ioctl, I2C_SLAVE failed: %d.\n", errno);
+ rv = -1;
+ goto fail;
+ }
+
+ for (index = 0; index < size; index++) {
+ data.byte = *(write_buf + index);
+ ioctl_data.read_write = I2C_SMBUS_WRITE;
+ ioctl_data.command = (offset_addr + index);
+ ioctl_data.size = I2C_SMBUS_BYTE_DATA;
+ ioctl_data.data= &data;
+ rv = ioctl(fd, I2C_SMBUS, (unsigned long)&ioctl_data);
+ if(rv < 0) {
+ DFD_DEBUG_ERROR("ioctl fail(ret:%d, errno:%s %d) !\r\n", rv, strerror(errno),errno);
+ break;
+ }
+ DFD_DEBUG_DBG("ret:%d value:0x%02x\n", rv, data.byte);
+ usleep(5000);
+ }
+
+fail:
+ close(fd);
+ return rv;
+}
+
+int32_t dfd_write_port_i2c(char *i2c_name, uint16_t dev_addr, uint16_t offset_addr,
+ uint8_t *write_buf, int32_t size)
+{
+ int i;
+ int rv;
+
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ rv = dfd_write_port_i2c_one_time(i2c_name, dev_addr, offset_addr, write_buf,size, DFD_I2C_SHORT_ADDR_TYPE);
+ if (rv < 0) {
+ DFD_DEBUG_ERROR("(write times %d)i2c name %s, dev_addr 0x%X, offset_addr 0x%X, addr_type %d\n",
+ i, i2c_name, dev_addr, offset_addr, DFD_I2C_SHORT_ADDR_TYPE);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+
+ return rv;
+}
+
+static int dfd_read_io_port(uint16_t offset_addr, uint8_t *recv_buf, int32_t size)
+{
+ int fd;
+ int ret;
+
+ fd = open("/dev/port", O_RDWR);
+ if (fd < 0) {
+ printf("open failed ret %d.\n", fd);
+ return -1;
+ }
+
+ ret = lseek(fd, offset_addr, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek failed ret %d.\n", ret);
+ goto exit;
+ }
+
+ ret = read(fd, recv_buf, size);
+ if (ret != size) {
+ printf("read failed ret %d size %d.\n", ret, size);
+ ret = -1;
+ goto exit;
+ }
+
+exit:
+ close(fd);
+ return ret;
+}
+
+static int dfd_write_io_port(uint16_t offset_addr, uint8_t *write_buf, int32_t size)
+{
+ int fd;
+ int ret;
+
+ fd = open("/dev/port", O_RDWR);
+ if (fd < 0) {
+ printf("open failed ret %d.\n", fd);
+ return -1;
+ }
+
+ ret = lseek(fd, offset_addr, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek failed ret %d.\n", ret);
+ goto exit;
+ }
+
+ ret = write(fd, write_buf, size);
+ if (ret != size) {
+ printf("write failed ret %d size %d.\n", ret, size);
+ ret = -1;
+ goto exit;
+ }
+
+exit:
+ close(fd);
+ return ret;
+}
+
+static int dfd_process_mem(char *dev_name, char is_wr, char width, off_t offset, uint8_t *buf, int32_t size)
+{
+ int mfd, ret = 0;
+ void *base;
+ int i, j;
+ unsigned int val;
+ off_t map_offset;
+ size_t map_size;
+
+ if (size & (width - 1)) {
+ printf("size %d invalid.\n", size);
+ return -1;
+ }
+
+ mfd = open(dev_name, O_RDWR);
+ if (mfd < 0) {
+ printf("Cannot open %s.\n", dev_name);
+ return -1;
+ }
+
+ g_sys_page_size = getpagesize();
+ map_offset = offset & SYS_PAGE_MASK;
+ map_size = size + offset - map_offset;
+ base = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, map_offset);
+ if (base == MAP_FAILED) {
+ printf("mmap offset 0x%lx failed error(%s).\n", map_offset, strerror(errno));
+ close(mfd);
+ return -1;
+ }
+ printf("width %d map_offset 0x%lx, offset 0x%lx, mmap base %p, g_sys_page_size %d\n",
+ width, map_offset, offset, base, g_sys_page_size);
+
+ if (is_wr) {
+ for (i = 0; i < size; i = i + width) {
+ val = 0;
+ for (j = 0; j < width; j++) {
+ val |= buf[i + j] << (8 * j);
+ }
+ switch (width) {
+ case 1:
+ *((volatile unsigned char*)(base + i + offset - map_offset)) = val;
+ break;
+ case 2:
+ *((volatile unsigned short*)(base + i + offset - map_offset)) = val;
+ break;
+ case 4:
+ *((volatile unsigned int*)(base + i + offset - map_offset)) = val;
+ break;
+ default:
+ ret = -1;
+ printf("Not support width %d.\n", width);
+ goto exit;
+ }
+ }
+ } else {
+ for (i = 0; i < size; i = i + width) {
+ switch (width) {
+ case 1:
+ val = *((volatile unsigned char*)(base + i + offset - map_offset));
+ break;
+ case 2:
+ val = *((volatile unsigned short*)(base + i + offset - map_offset));
+ break;
+ case 4:
+ val = *((volatile unsigned int*)(base + i + offset - map_offset));
+ break;
+ default:
+ ret = -1;
+ printf("Not support width %d.\n", width);
+ goto exit;
+ }
+ for (j = 0; j < width; j++) {
+ buf[i + j] = (val >> (8 * j)) & 0xff;
+ }
+ }
+ }
+exit:
+ munmap(base, map_size);
+ close(mfd);
+ return ret;
+}
+
+int32_t dfd_i2c_gen_read_one_time(char *i2c_path, uint32_t dev_addr, uint32_t addr_bitwidth,
+ uint32_t offset_addr, uint8_t *recv_buf, int32_t rd_len)
+{
+ int32_t fd, rv, i;
+ struct i2c_rdwr_ioctl_data ioctl_data;
+ struct i2c_msg msgs[2];
+ uint8_t buf[DFD_UTEST_MAX_BIT_WIDTH];
+
+ fd = open(i2c_path, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ DFD_DEBUG_ERROR("i2c open fail fd:%d\n", fd);
+ return -1;
+ }
+ mem_clear(&ioctl_data, sizeof(ioctl_data));
+ mem_clear(msgs, sizeof(msgs));
+ mem_clear(buf, sizeof(buf));
+
+ i = 0;
+
+ switch (addr_bitwidth) {
+ case WIDTH_4Byte:
+ buf[i++] = (offset_addr >> 24) & 0xFF;
+ buf[i++] = (offset_addr >> 16) & 0xFF;
+ buf[i++] = (offset_addr >> 8) & 0xFF;
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ case WIDTH_2Byte:
+ buf[i++] = (offset_addr >> 8) & 0xFF;
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ case WIDTH_1Byte:
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ default:
+ DFD_DEBUG_ERROR("Only support 1,2,4 Byte Address Width,but set %u addr_bitwidth \n", addr_bitwidth);
+ rv = -1;
+ goto fail;
+ }
+
+ msgs[0].addr = dev_addr;
+ msgs[0].flags = 0;
+ msgs[0].len = addr_bitwidth;
+ msgs[0].buf = buf;
+ msgs[1].addr = dev_addr;
+ msgs[1].flags |= I2C_M_RD;
+ msgs[1].len = rd_len;
+ msgs[1].buf = recv_buf;
+ ioctl_data.nmsgs = 2;
+ ioctl_data.msgs = msgs;
+
+ rv = ioctl(fd, I2C_RDWR, &ioctl_data);
+ if(rv < 0) {
+ DFD_DEBUG_ERROR("%s %d Error: Sending messages failed:(ret:%d, errno:%s)!\n", __func__ , __LINE__, rv, strerror(errno));
+ goto fail;
+ }
+
+fail:
+ close(fd);
+ return rv;
+}
+
+int32_t dfd_i2c_gen_read(char *i2c_path, uint32_t dev_addr, uint32_t addr_bitwidth,
+ uint32_t offset_addr, uint8_t *recv_buf, int32_t rd_len)
+{
+ int i;
+ int rv;
+
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ rv = dfd_i2c_gen_read_one_time(i2c_path, dev_addr, addr_bitwidth, offset_addr, recv_buf, rd_len);
+ if (rv < 0) {
+ DFD_DEBUG_ERROR("(read times:%d) i2c_path:%s, dev_addr:0x%x, addr_bitwidth:%u, offset_addr:0x%x, rd_len:%u\n",
+ i, i2c_path, dev_addr, addr_bitwidth, offset_addr, rd_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+
+ return rv;
+}
+
+int dfd_utest_i2c_gen_rd(int argc, char* argv[])
+{
+ int ret;
+ uint32_t i2c_bus, dev_addr, addr_bitwidth, offset_addr, data_bitwidth, rd_len, i, j;
+ char *stopstring;
+ char i2c_path[32];
+ uint8_t tmp_value[DFD_UTEST_MAX_RDWR_NUM];
+ uint8_t rd_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc != 8) {
+ DFD_DEBUG_ERROR("params error\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_GEN_RD);
+ goto exit;
+ }
+
+ i2c_bus = strtol(argv[2], &stopstring, 10);
+ dev_addr = strtol(argv[3], &stopstring, 16);
+ addr_bitwidth = strtol(argv[4], &stopstring, 10);
+ offset_addr = strtol(argv[5], &stopstring, 16);
+ data_bitwidth = strtol(argv[6], &stopstring, 10);
+ rd_len = strtol(argv[7], &stopstring, 10);
+
+ if (rd_len > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", rd_len);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_GEN_RD);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+ snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_bus);
+ mem_clear(tmp_value, sizeof(tmp_value));
+ ret = dfd_i2c_gen_read(i2c_path, dev_addr, addr_bitwidth, offset_addr, tmp_value, rd_len);
+ if (ret < 0) {
+ printf("read failed. ret:%d\n", ret);
+ goto exit;
+ }
+
+ mem_clear(rd_value, sizeof(rd_value));
+ if (data_bitwidth == WIDTH_1Byte) {
+ memcpy(rd_value, tmp_value, rd_len);
+ } else {
+ for (i = 0; i < rd_len; i += data_bitwidth) {
+ for (j = 0; (j < data_bitwidth) && (i + j < rd_len); j++) {
+ rd_value[i + data_bitwidth - j - 1] = tmp_value[i + j];
+ }
+ }
+ }
+
+ dfd_utest_printf_reg(rd_value, rd_len, offset_addr);
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int32_t dfd_i2c_gen_write_one_time(char *i2c_path, uint32_t dev_addr, uint32_t addr_bitwidth,
+ uint32_t offset_addr, uint8_t *wr_value, uint32_t wr_len)
+{
+ int32_t fd, rv, i;
+ struct i2c_rdwr_ioctl_data ioctl_data;
+ struct i2c_msg msgs[1];
+ uint8_t buf[DFD_UTEST_MAX_BIT_WIDTH + DFD_UTEST_MAX_RDWR_NUM];
+
+ fd = open(i2c_path, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ DFD_DEBUG_ERROR("i2c open fail fd %d\n", fd);
+ return -1;
+ }
+ mem_clear(&ioctl_data, sizeof(ioctl_data));
+ mem_clear(msgs, sizeof(msgs));
+ mem_clear(buf, sizeof(buf));
+
+ i = 0;
+
+ switch (addr_bitwidth) {
+ case WIDTH_4Byte:
+ buf[i++] = (offset_addr >> 24) & 0xFF;
+ buf[i++] = (offset_addr >> 16) & 0xFF;
+ buf[i++] = (offset_addr >> 8) & 0xFF;
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ case WIDTH_2Byte:
+ buf[i++] = (offset_addr >> 8) & 0xFF;
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ case WIDTH_1Byte:
+ buf[i++] = offset_addr & 0xFF;
+ break;
+ default:
+ DFD_DEBUG_ERROR("Only support 1,2,4 Byte Address Width,but set %u addr_bitwidth \r\n", addr_bitwidth);
+ rv = -1;
+ goto fail;
+ }
+
+ memcpy(buf + addr_bitwidth, wr_value, wr_len);
+
+ msgs[0].addr= dev_addr;
+ msgs[0].flags = 0;
+ msgs[0].len= addr_bitwidth + wr_len;
+ msgs[0].buf= buf;
+
+ ioctl_data.nmsgs= 1;
+ ioctl_data.msgs= msgs;
+
+ rv = ioctl(fd, I2C_RDWR, &ioctl_data);
+ if(rv < 0) {
+ DFD_DEBUG_ERROR("%s %dError: Sending messages failed:(ret:%d, errno:%s)!\n", __func__ , __LINE__, rv, strerror(errno));
+ goto fail;
+ } else if (rv < ioctl_data.nmsgs) {
+ DFD_DEBUG_ERROR("%s %dWarning: only %d/%d messages were sent\n", __func__ , __LINE__, rv, ioctl_data.nmsgs);
+ }
+
+fail:
+ close(fd);
+ return rv;
+}
+
+int32_t dfd_i2c_gen_write(char *i2c_path, uint32_t dev_addr, uint32_t addr_bitwidth,
+ uint32_t offset_addr, uint8_t *wr_value, uint32_t wr_len)
+{
+ int i;
+ int rv;
+
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ rv = dfd_i2c_gen_write_one_time(i2c_path, dev_addr, addr_bitwidth, offset_addr, wr_value, wr_len);
+ if (rv < 0) {
+ DFD_DEBUG_ERROR("(write times:%d)i2c_path:%s, dev_addr:0x%x, addr_bitwidth:%u, offset_addr:0x%x, wr_len:%u\n",
+ i, i2c_path, dev_addr, addr_bitwidth, offset_addr, wr_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+
+ return rv;
+}
+
+int dfd_utest_i2c_gen_wr(int argc, char* argv[])
+{
+ int ret;
+ uint32_t i2c_bus, dev_addr, addr_bitwidth, offset_addr, data_bitwidth, wr_len, tmp_data, para_len, i, j;
+ char *stopstring;
+ char i2c_path[32];
+ uint8_t wr_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc < 8) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_GEN_WR);
+ goto exit;
+ }
+
+ i2c_bus = strtol(argv[2], &stopstring, 10);
+ dev_addr = strtol(argv[3], &stopstring, 16);
+ addr_bitwidth = strtol(argv[4], &stopstring, 10);
+ offset_addr = strtol(argv[5], &stopstring, 16);
+ data_bitwidth = strtol(argv[6], &stopstring, 10);
+
+ para_len = argc - 7;
+ wr_len = para_len * data_bitwidth;
+
+ if (wr_len > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", wr_len);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_GEN_WR);
+ goto exit;
+ }
+
+ if (data_bitwidth == WIDTH_1Byte) {
+ for (i = 0; i < para_len; i++) {
+ wr_value[i] = strtol(argv[7 + i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value 0x%x\n", i , wr_value[i]);
+ }
+ } else {
+ for (i = 0; i < para_len; i++) {
+ tmp_data = strtol(argv[7 + i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value 0x%x\n", i , tmp_data);
+ for (j = 0; j < data_bitwidth; j++) {
+ tmp_data = strtol(argv[7 + i], &stopstring, 16);
+ wr_value[j + i * data_bitwidth] = (tmp_data >> (24 - 8 * j)) & 0xFF;
+ }
+ }
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_bus);
+
+ ret = dfd_i2c_gen_write(i2c_path, dev_addr, addr_bitwidth, offset_addr, wr_value, wr_len);
+ if (ret < 0) {
+ printf("write failed. ret:%d\n", ret);
+ } else {
+ printf("write success\n");
+ }
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_i2c_rd(int argc, char* argv[])
+{
+ int ret;
+ uint8_t value[DFD_UTEST_MAX_RDWR_NUM];
+ uint16_t dev_addr, offset_addr;
+ char *stopstring;
+ int num, i2c_bus;
+ char i2c_path[32];
+
+ if (argc != 6) {
+ DFD_DEBUG_ERROR("params error\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_RD);
+ goto exit;
+ }
+
+ i2c_bus = strtol(argv[2], &stopstring, 10);
+ dev_addr = strtol(argv[3], &stopstring, 16);
+ offset_addr = strtol(argv[4], &stopstring, 16);
+ num = strtol(argv[5], &stopstring, 10);
+
+ if (num > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", num);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_RD);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+ snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_bus);
+ mem_clear(value, sizeof(value));
+ ret = dfd_read_port_i2c(i2c_path, dev_addr, offset_addr, value, num);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ goto exit;
+ }
+
+ dfd_utest_printf_reg(value, num, offset_addr);
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+
+}
+
+int dfd_utest_i2c_wr(int argc, char* argv[])
+{
+ int ret;
+ uint16_t dev_addr, offset_addr;
+ char *stopstring;
+ int i2c_bus;
+ char i2c_path[32];
+ uint8_t wr_len,i;
+ uint8_t wr_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc < 6) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_WR);
+ goto exit;
+ }
+
+ wr_len = argc - 5;
+ i2c_bus = strtol(argv[2], &stopstring, 10);
+ dev_addr = strtol(argv[3], &stopstring, 16);
+ offset_addr = strtol(argv[4], &stopstring, 16);
+
+ for (i = 0; i < wr_len; i++) {
+ wr_value[i] = strtol(argv[5+i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value %x\n", i , wr_value[i]);
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_bus);
+
+ ret = dfd_write_port_i2c(i2c_path, dev_addr, offset_addr, wr_value, wr_len);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ } else {
+ printf("success\n");
+ }
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_io_rd(int argc, char* argv[])
+{
+ int ret;
+ uint8_t value[DFD_UTEST_MAX_RDWR_NUM];
+ uint16_t offset_addr;
+ char *stopstring;
+ int num;
+
+ if (argc != 4) {
+ DFD_DEBUG_ERROR("params error\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_IO_RD);
+ goto exit;
+ }
+
+ offset_addr = strtol(argv[2], &stopstring, 16);
+ num = strtol(argv[3], &stopstring, 10);
+
+ if (num > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", num);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_IO_RD);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+ mem_clear(value, sizeof(value));
+ ret = dfd_read_io_port(offset_addr, value, num);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ goto exit;
+ }
+
+ dfd_utest_printf_reg(value, num, offset_addr);
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_io_wr(int argc, char* argv[])
+{
+ int ret;
+ uint16_t offset_addr;
+ char *stopstring;
+ int32_t wr_len,i;
+ uint8_t wr_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc < 4) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_IO_WR);
+ goto exit;
+ }
+
+ wr_len = argc - 3;
+ if (wr_len > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", wr_len);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_IO_WR);
+ goto exit;
+ }
+
+ offset_addr = strtol(argv[2], &stopstring, 16);
+
+ for (i = 0; i < wr_len; i++) {
+ wr_value[i] = strtol(argv[3 + i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value %x\n", i , wr_value[i]);
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ ret = dfd_write_io_port(offset_addr, wr_value, wr_len);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ } else {
+ printf("success\n");
+ }
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_phymem_rd(int argc, char* argv[])
+{
+ int ret, width;
+ uint8_t value[DFD_UTEST_MAX_RDWR_NUM];
+ off_t offset_addr;
+ char *stopstring;
+ int num;
+
+ if (argc != 5) {
+ DFD_DEBUG_ERROR("params error\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_PHYMEM_RD);
+ goto exit;
+ }
+
+ width = strtol(argv[2], &stopstring, 10);
+ offset_addr = strtol(argv[3], &stopstring, 16);
+ num = strtol(argv[4], &stopstring, 10);
+
+ if (num > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", num);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_PHYMEM_RD);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+ mem_clear(value, sizeof(value));
+ ret = dfd_process_mem(DEV_MEM_NAME, 0, width, offset_addr, value, num);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ goto exit;
+ }
+
+ dfd_utest_printf_reg(value, num, offset_addr);
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_phymem_wr(int argc, char* argv[])
+{
+ int ret, width;
+ off_t offset_addr;
+ char *stopstring;
+ int32_t wr_len,i;
+ uint8_t wr_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc < 5) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_PHYMEM_WR);
+ goto exit;
+ }
+
+ wr_len = argc - 4;
+ if (wr_len > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", wr_len);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_PHYMEM_WR);
+ goto exit;
+ }
+
+ width = strtol(argv[2], &stopstring, 10);
+ offset_addr = strtol(argv[3], &stopstring, 16);
+
+ for (i = 0; i < wr_len; i++) {
+ wr_value[i] = strtol(argv[4 + i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value %x\n", i , wr_value[i]);
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ ret = dfd_process_mem(DEV_MEM_NAME, 1, width, offset_addr, wr_value, wr_len);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ } else {
+ printf("success\n");
+ }
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_kmem_rd(int argc, char* argv[])
+{
+ int ret, width;
+ uint8_t value[DFD_UTEST_MAX_RDWR_NUM];
+ uint16_t offset_addr;
+ char *stopstring;
+ int num;
+
+ if (argc != 5) {
+ DFD_DEBUG_ERROR("params error\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_KMEM_RD);
+ goto exit;
+ }
+
+ width = strtol(argv[2], &stopstring, 10);
+ offset_addr = strtol(argv[3], &stopstring, 16);
+ num = strtol(argv[4], &stopstring, 10);
+
+ if (num > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", num);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_KMEM_RD);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+ mem_clear(value, sizeof(value));
+ ret = dfd_process_mem(DEV_KMEM_NAME, 0, width, offset_addr, value, num);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ goto exit;
+ }
+
+ dfd_utest_printf_reg(value, num, offset_addr);
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_kmem_wr(int argc, char* argv[])
+{
+ int ret;
+ uint16_t offset_addr, width;
+ char *stopstring;
+ int32_t wr_len,i;
+ uint8_t wr_value[DFD_UTEST_MAX_RDWR_NUM];
+
+ if (argc < 5) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_KMEM_WR);
+ goto exit;
+ }
+
+ wr_len = argc - 4;
+ if (wr_len > DFD_UTEST_MAX_RDWR_NUM) {
+ DFD_DEBUG_ERROR("Input num %d exceed max.\n", wr_len);
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_KMEM_WR);
+ goto exit;
+ }
+
+ width = strtol(argv[2], &stopstring, 10);
+ offset_addr = strtol(argv[3], &stopstring, 16);
+
+ for (i = 0; i < wr_len; i++) {
+ wr_value[i] = strtol(argv[4 + i], &stopstring, 16);
+ DFD_DEBUG_DBG(" index :%d value %x\n", i , wr_value[i]);
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ ret = dfd_process_mem(DEV_KMEM_NAME, 1, width, offset_addr, wr_value, wr_len);
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ } else {
+ printf("success\n");
+ }
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+static unsigned long dfd_utest_get_file_size(const char *path)
+{
+ unsigned long filesize;
+ struct stat statbuff;
+
+ if (stat(path, &statbuff) < 0) {
+ filesize = -1;
+ } else {
+ filesize = statbuff.st_size;
+ }
+
+ return filesize;
+}
+
+int dfd_utest_i2c_file_wr(int argc, char* argv[])
+{
+ int ret;
+ uint16_t dev_addr, offset_addr;
+ char *stopstring;
+ int i2c_bus;
+ char i2c_path[32];
+ char *file_name;
+ unsigned long filesize;
+ int fd;
+ uint8_t wr_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int len;
+ int bpt; /* byte per times*/
+ int page_left;
+
+ if (argc != 7) {
+ printf("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_I2C_FILE_WR);
+ goto exit;
+ }
+
+ i2c_bus = strtol(argv[2], &stopstring, 10);
+ dev_addr = strtol(argv[3], &stopstring, 16);
+ offset_addr = strtol(argv[4], &stopstring, 16);
+ bpt = strtol(argv[5], &stopstring, 10);
+ file_name = argv[6];
+
+ if ((bpt <= 0) || (bpt > DFD_UTEST_MAX_RDWR_NUM)) {
+ bpt = DFD_UTEST_MAX_RDWR_NUM;
+ }
+
+ if ((bpt & (bpt - 1)) != 0) {
+ printf("Bytes per times %d isn't power of two.\n",bpt);
+ goto exit;
+ }
+
+ filesize = dfd_utest_get_file_size(file_name);
+ if (filesize <= 0) {
+ printf("Input invalid file %s, filesize %lu.\n", file_name, filesize);
+ goto exit;
+ }
+
+ fd = open(file_name, O_RDONLY);
+ if (fd < 0) {
+ printf("open file[%s] fail.\n", file_name);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+ snprintf(i2c_path, sizeof(i2c_path), "/dev/i2c-%d", i2c_bus);
+
+ while (filesize > 0) {
+ mem_clear(wr_buf, DFD_UTEST_MAX_RDWR_NUM);
+ len = bpt;
+ if (offset_addr & (bpt - 1)) {
+ page_left = bpt - (offset_addr & (bpt - 1));
+ len = len > page_left ? page_left : len;
+ }
+
+ len = read(fd, wr_buf, len);
+
+ ret = dfd_write_port_i2c(i2c_path, dev_addr, offset_addr, wr_buf, len);
+ if (ret < 0) {
+ break;
+ }
+ offset_addr += len;
+ filesize -= len;
+ }
+
+ close(fd);
+
+ if (ret < 0) {
+ printf("failed ret %d\n", ret);
+ } else {
+ printf("success\n");
+ }
+
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+
+}
+
+/* compare with sys_flie_wr, One more step is read back verification */
+int dfd_utest_sysfs_file_upg(int argc, char* argv[])
+{
+ int ret = 0;
+ uint32_t offset_addr;
+ char *file_name;
+ char *sysfs_loc;
+ char *stopstring;
+ unsigned long filesize;
+ int fd, file_fd;
+ uint8_t wr_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int len, write_len, per_wr_len;
+ int i;
+ uint8_t reread_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int reback_len, reread_len;
+ int j = 0;
+
+ if (argc != 5 && argc != 6) {
+ printf("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_SYSFS_FILE_UPG);
+ goto exit;
+ }
+
+ sysfs_loc = argv[2];
+ offset_addr = strtol(argv[3], &stopstring, 16);
+ file_name = argv[4];
+
+ if (argc == 6) {
+ per_wr_len = strtol(argv[5], &stopstring, 10);
+ if (per_wr_len > DFD_UTEST_MAX_RDWR_NUM || per_wr_len <= 0) {
+ printf("per_wr_byte %d invalid, not in range (0, 256]\n", per_wr_len);
+ goto exit;
+ }
+ } else {
+ per_wr_len = DFD_UTEST_DEFAULT_WR_NUM;
+ }
+ DFD_DEBUG_DBG("per_wr_byte: %d\n", per_wr_len);
+ filesize = dfd_utest_get_file_size(file_name);
+ if (filesize <= 0) {
+ printf("Input invalid file %s, filesize %lu.\n", file_name, filesize);
+ goto exit;
+ }
+
+ fd = open(sysfs_loc, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ printf("open file[%s] fail.\n", sysfs_loc);
+ goto exit;
+ }
+
+ file_fd = open(file_name, O_RDONLY);
+ if (file_fd < 0) {
+ printf("open file[%s] fail.\n", file_name);
+ goto open_dev_err;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ ret = lseek(fd, offset_addr, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek file[%s offset=%d] fail,\n", sysfs_loc, offset_addr);
+ goto fail;
+ }
+
+ printf(":\n");
+ while (filesize > 0) {
+ if (filesize > (unsigned long)per_wr_len) {
+ len = per_wr_len;
+ } else {
+ len = filesize;
+ }
+
+ mem_clear(wr_buf, DFD_UTEST_MAX_RDWR_NUM);
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ len = read(file_fd, wr_buf, len);
+ if (len < 0) {
+ DFD_DEBUG_ERROR("read file[%s] fail, offset = 0x%x retrytimes = %d ret = %d\n",
+ sysfs_loc, offset_addr, i ,len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+ if (i == DFD_I2C_RETRY_TIME) {
+ printf("read file[%s] fail, offset = 0x%x, ret = %d\n", sysfs_loc, offset_addr, len);
+ goto fail;
+ }
+
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ write_len = write(fd, wr_buf, len);
+ if (write_len != len) {
+ DFD_DEBUG_ERROR("write file[%s] fail,offset = 0x%x retrytimes = %d len = %d,write_len =%d\n",
+ sysfs_loc, offset_addr, i ,len, write_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+ if (i == DFD_I2C_RETRY_TIME) {
+ printf("write file[%s] fail, offset = 0x%x, len = %d,write_len =%d\n",
+ sysfs_loc, offset_addr, len, write_len);
+ goto fail;
+ }
+
+ reback_len = write_len;
+ ret = lseek(fd, -reback_len, SEEK_CUR);
+ if (ret < 0) {
+ printf("reread lseek file[%s offset=%d] fail,lseek len=%d\n",
+ sysfs_loc, offset_addr, reback_len);
+ goto fail;
+ }
+
+ mem_clear(reread_buf, DFD_UTEST_MAX_RDWR_NUM);
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ reread_len = read(fd, reread_buf, reback_len);
+ if (reread_len != reback_len) {
+ DFD_DEBUG_ERROR("reread file[%s] fail,offset = 0x%x retrytimes = %d reread_len = %d,reback_len =%d\n",
+ sysfs_loc, offset_addr, i ,reread_len, reback_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+ if (i == DFD_I2C_RETRY_TIME) {
+ printf("reread file[%s] fail, offset = 0x%x, reread_len = %d,reback_len = %d\n",
+ sysfs_loc, offset_addr, reread_len, reback_len);
+ goto fail;
+ }
+
+ if (memcmp(reread_buf, wr_buf, reread_len) != 0) {
+ if (j < DFD_I2C_RETRY_TIME) {
+ DFD_DEBUG_ERROR("memcmp file[%s] fail,offset = 0x%x retrytimes = %d\n",
+ sysfs_loc, offset_addr, j);
+ j++;
+ ret = lseek(file_fd, -len, SEEK_CUR);
+ if (ret < 0) {
+ printf("retry file_fd lseek fail,lseek len=%d\n", len);
+ goto fail;
+ }
+ ret = lseek(fd, -write_len, SEEK_CUR);
+ if (ret < 0) {
+ printf("retry fd lseek fail,lseek len=%d\n", write_len);
+ goto fail;
+ }
+ continue;
+ }
+
+ printf("upgrade file[%s] fail, offset = 0x%x.\n", sysfs_loc, offset_addr);
+ printf("want to write buf :\n");
+ for (i = 0; i < reread_len; i++) {
+ printf("0x%x ", wr_buf[i]);
+ }
+ printf("\n");
+
+ printf("actually reread buf :\n");
+ for (i = 0; i < reread_len; i++) {
+ printf("0x%x ", reread_buf[i]);
+ }
+ printf("\n");
+
+ goto fail;
+ }
+
+ offset_addr += len;
+ filesize -= len;
+ usleep(5000);
+ }
+
+ printf("success\n");
+ close(file_fd);
+ close(fd);
+ return DFD_RV_OK;
+
+fail:
+ close(file_fd);
+open_dev_err:
+ close(fd);
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_sysfs_file_wr(int argc, char* argv[])
+{
+ int ret = 0;
+ uint32_t offset_addr;
+ char *file_name;
+ char *sysfs_loc;
+ char *stopstring;
+ unsigned long filesize;
+ int fd, file_fd;
+ uint8_t wr_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int len, write_len, per_wr_len;
+ int i;
+
+ if (argc != 5 && argc != 6) {
+ printf("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_SYSFS_FILE_WR);
+ goto exit;
+ }
+
+ sysfs_loc = argv[2];
+ offset_addr = strtol(argv[3], &stopstring, 16);
+ file_name = argv[4];
+
+ if (argc == 6) {
+ per_wr_len = strtol(argv[5], &stopstring, 10);
+ if (per_wr_len > DFD_UTEST_MAX_RDWR_NUM || per_wr_len <= 0) {
+ printf("per_wr_byte %d invalid, not in range (0, 256]\n", per_wr_len);
+ goto exit;
+ }
+ } else {
+ per_wr_len = DFD_UTEST_DEFAULT_WR_NUM;
+ }
+ DFD_DEBUG_DBG("per_wr_byte: %d\n", per_wr_len);
+ filesize = dfd_utest_get_file_size(file_name);
+ if (filesize <= 0) {
+ printf("Input invalid file %s, filesize %lu.\n", file_name, filesize);
+ goto exit;
+ }
+
+ fd = open(sysfs_loc, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ printf("open file[%s] fail.\n", sysfs_loc);
+ goto exit;
+ }
+
+ file_fd = open(file_name, O_RDONLY);
+ if (file_fd < 0) {
+ printf("open file[%s] fail.\n", file_name);
+ goto open_dev_err;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+
+ ret = lseek(fd, offset_addr, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek file[%s offset=%d] fail,\n", sysfs_loc, offset_addr);
+ goto fail;
+ }
+
+ printf(":\n");
+ while (filesize > 0) {
+ if (filesize > (unsigned long)per_wr_len) {
+ len = per_wr_len;
+ } else {
+ len = filesize;
+ }
+
+ mem_clear(wr_buf, DFD_UTEST_MAX_RDWR_NUM);
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ len = read(file_fd, wr_buf, len);
+ if (len < 0) {
+ DFD_DEBUG_ERROR("read file[%s] fail, offset = 0x%x retrytimes = %d ret = %d\n",
+ sysfs_loc, offset_addr, i ,len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+ if (i == DFD_I2C_RETRY_TIME) {
+ printf("read file[%s] fail, offset = 0x%x, ret = %d\n", sysfs_loc, offset_addr, len);
+ goto fail;
+ }
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ write_len = write(fd, wr_buf, len);
+ if (write_len != len) {
+ DFD_DEBUG_ERROR("write file[%s] fail,offset = 0x%x retrytimes = %d len = %d,write_len =%d\n", sysfs_loc, offset_addr, i ,len, write_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ break;
+ }
+
+ if(i == DFD_I2C_RETRY_TIME) {
+ printf("write file[%s] fail, offset = 0x%x, len = %d,write_len =%d\n", sysfs_loc, offset_addr, len, write_len);
+ ret = -1;
+ goto fail;
+ }
+ offset_addr += len;
+ filesize -= len;
+ usleep(5000);
+ }
+
+ printf("success\n");
+ close(file_fd);
+ close(fd);
+ return DFD_RV_OK;
+
+fail:
+ close(file_fd);
+open_dev_err:
+ close(fd);
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_sysfs_file_rd(int argc, char* argv[])
+{
+ int ret = 0;
+ uint32_t offset_addr;
+ char *sysfs_loc;
+ char *stopstring;
+ int fd;
+ uint8_t rd_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int len, read_len;;
+
+ if (argc != 5) {
+ printf("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_SYSFS_FILE_RD);
+ goto exit;
+ }
+
+ sysfs_loc = argv[2];
+ offset_addr = strtol(argv[3], &stopstring, 16);
+ len = strtol(argv[4], &stopstring, 10);
+
+ if (len > DFD_UTEST_MAX_RDWR_NUM) {
+ printf("Input num %d exceed max 256.\n", len);
+ goto exit;
+ }
+
+ fd = open(sysfs_loc, O_RDONLY);
+ if (fd < 0) {
+ printf("open file[%s] fail.\n", sysfs_loc);
+ goto exit;
+ }
+ dfd_utest_print_cmd(argc, argv);
+
+ printf(":\n");
+
+ ret = lseek(fd, offset_addr, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek failed ret %d.\n", ret);
+ goto fail;
+ }
+
+ mem_clear(rd_buf, DFD_UTEST_MAX_RDWR_NUM);
+ read_len = read(fd, rd_buf, len);
+ if (read_len != len) {
+ printf("read failed read_len %d len %d.\n", read_len, len);
+ goto fail;
+ }
+ dfd_utest_printf_reg(rd_buf, read_len, offset_addr);
+ close(fd);
+ return DFD_RV_OK;
+
+fail:
+ close(fd);
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_msr_rd(int argc, char* argv[])
+{
+ int fd;
+ char msr_file_name[64];
+ uint64_t data;
+ uint64_t read_result;
+ char *stopstring;
+ uint8_t cpu_index, width;
+ uint64_t offset;
+
+ if (argc != 5) {
+ printf("rdmsr failed: Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_MSR_RD);
+ goto exit;
+ }
+
+ cpu_index = strtol(argv[2], &stopstring, 10);
+ offset = strtol(argv[3], &stopstring, 16);
+ width = strtol(argv[4], &stopstring, 10);
+
+ if (width != 8 && width != 16 && width != 32 && width != 64) {
+ printf("rdmsr failed: width:%u Input invalid.only support 8 16 32 64\n", width);
+ goto exit;
+ }
+
+ mem_clear(msr_file_name, sizeof(msr_file_name));
+ sprintf(msr_file_name, "/dev/cpu/%u/msr", cpu_index);
+
+ fd = open(msr_file_name, O_RDONLY);
+ if (fd < 0) {
+ if (errno == ENXIO) {
+ fprintf(stderr, "rdmsr failed: No CPU %u\n", cpu_index);
+ } else if (errno == EIO) {
+ fprintf(stderr, "rdmsr failed: CPU %u doesn't support MSRs\n", cpu_index);
+ } else if (errno == ENOENT) {
+ fprintf(stderr, "rdmsr failed: can't find %s file, Please check if modprobe msr driver already\n", msr_file_name);
+ } else {
+ printf("rdmsr failed: %s open failed. errno:%d\n", msr_file_name, errno);
+ }
+ goto exit;
+ }
+
+ if (pread(fd, &data, sizeof(data), offset) != sizeof(data)) {
+ fprintf(stderr, "rdmsr failed: CPU:%u offset:0x%lx read failed\n", cpu_index, offset);
+ goto fail;
+ }
+
+ switch (width) {
+ case 8:
+ read_result = (volatile uint8_t)data;
+ break;
+ case 16:
+ read_result = (volatile uint16_t)data;
+ break;
+ case 32:
+ read_result = (volatile uint32_t)data;
+ break;
+ case 64:
+ read_result = (volatile uint64_t)data;
+ break;
+ default:
+ printf("rdmsr failed: width:%u illegal width.\n", width);
+ goto fail;
+ }
+
+ printf("0x%lx\n", read_result);
+ close(fd);
+ return DFD_RV_OK;
+
+fail:
+ close(fd);
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+int dfd_utest_sysfs_data_wr(int argc, char* argv[])
+{
+ uint32_t offset;
+ char *sysfs_loc;
+ char *stopstring;
+ uint8_t wr_buf[DFD_UTEST_MAX_RDWR_NUM];
+ int ret, i;
+ int fd, len, write_len, index;
+
+ if (argc < 5) {
+ DFD_DEBUG_ERROR("Input invalid.\n");
+ dfd_utest_printf_single_help(DFD_UTEST_ITEM_SYSFS_DATA_WR);
+ goto exit;
+ }
+
+ dfd_utest_print_cmd(argc, argv);
+ printf(":\n");
+
+ sysfs_loc = argv[2];
+ offset = strtol(argv[3], &stopstring, 16);
+ len = argc - 4;
+ mem_clear(wr_buf, sizeof(wr_buf));
+ for (i = 0; i < len; i++) {
+ wr_buf[i] = strtol(argv[4 + i], &stopstring, 16);
+ DFD_DEBUG_DBG("index :%d value %x\n", i , wr_buf[i]);
+ }
+
+ fd = open(sysfs_loc, O_RDWR | O_SYNC);
+ if (fd < 0) {
+ printf("open file[%s] fail.\n", sysfs_loc);
+ goto exit;
+ }
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0) {
+ printf("lseek file[%s offset=%d] fail,\n", sysfs_loc, offset);
+ goto fail;
+ }
+ index = 0;
+ while (len > 0) {
+ for (i = 0; i < DFD_I2C_RETRY_TIME; i++) {
+ write_len = write(fd, &wr_buf[index], len);
+ if (write_len < 0) {
+ DFD_DEBUG_ERROR("write file[%s] fail, retrytimes: %d, offset: 0x%x, len: %d, write_len: %d\n",
+ sysfs_loc, offset, i, len, write_len);
+ usleep(DFD_I2C_RETRY_SLEEP_TIME);
+ continue;
+ }
+ if (write_len == 0) {
+ DFD_DEBUG_ERROR("write file[%s] EOF, offset: 0x%x, len: %d, write_len: %d\n",
+ sysfs_loc, offset, len, write_len);
+ goto fail;
+ }
+ break;
+ }
+ if(i == DFD_I2C_RETRY_TIME) {
+ printf("write file[%s] fail, offset: 0x%x, len: %d, write_len: %d\n",
+ sysfs_loc, offset, len, write_len);
+ goto fail;
+ }
+ offset += write_len;
+ index += write_len;
+ len -= write_len;
+ usleep(5000);
+ }
+ printf("success\n");
+ close(fd);
+ return DFD_RV_OK;
+fail:
+ close(fd);
+exit:
+ return DFD_RV_MODE_NOTSUPPORT;
+}
+
+dfd_utest_proc_fun dfd_utest_get_proc_func(char *type_str)
+{
+ int i, tbl_size;
+
+ tbl_size = sizeof(g_dfd_unit_test) / sizeof(g_dfd_unit_test[0]);
+
+ for (i = 0; i < tbl_size; i++) {
+ if (!strncmp(g_dfd_unit_test[i].type_str, type_str, strlen(g_dfd_unit_test[i].type_str))) {
+ return g_dfd_unit_test[i].utest_func;
+ }
+ }
+ DFD_DEBUG_DBG("type: %s not match.\n", type_str);
+ return NULL;
+}
+
+void dfd_utest_cmd_main(int argc, char* argv[])
+{
+ dfd_utest_proc_fun pfunc;
+ int ret;
+
+ if (argc < 2) {
+ dfd_utest_print_all_help();
+ return;
+ }
+
+ pfunc = dfd_utest_get_proc_func(argv[1]);
+ if (pfunc == NULL) {
+ DFD_DEBUG_DBG("utest type %s in not support.\n", argv[1]);
+ dfd_utest_print_all_help();
+ return;
+ }
+ ret = pfunc(argc, argv);
+ if ((ret != DFD_RV_MODE_NOTSUPPORT) && (ret != DFD_RV_INDEX_INVALID)) {
+ if (ret == DFD_RV_OK) {
+ DFD_DEBUG_DBG(" [SUCCESS]\n");
+ } else {
+ DFD_DEBUG_DBG(" [FAIL(%d)]\n", ret);
+ }
+ }
+
+ return;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.h
new file mode 100644
index 0000000000..aa194a4dcd
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/dev_util/dfd_utest.h
@@ -0,0 +1,103 @@
+/* monitor_utest.h */
+#ifndef __DFD_UTEST_H__
+#define __DFD_UTEST_H__
+
+#include
+
+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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile
new file mode 100644
index 0000000000..62663efdbb
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Makefile
@@ -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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk
new file mode 100644
index 0000000000..5fb5a09d34
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/Rules.mk
@@ -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)
+
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/Makefile
new file mode 100644
index 0000000000..e8879aeff5
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/Makefile
@@ -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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/Makefile
new file mode 100644
index 0000000000..0add28cb90
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware.c
new file mode 100644
index 0000000000..db72b36946
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware.c
@@ -0,0 +1,144 @@
+#include
+#include
+#include
+
+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");
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld.c
new file mode 100644
index 0000000000..18ec509d0f
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld.c
@@ -0,0 +1,384 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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);
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld_upgrade.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld_upgrade.c
new file mode 100644
index 0000000000..8252c2a39b
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/firmware_cpld_upgrade.c
@@ -0,0 +1,1879 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* CPLD file parses the relevant parameters */
+#define CPLD_HEX 16
+#define DEC_VAL 10
+#define CPLD_INIT_CNT 4
+#define CPLD_UNIT_SZ 4
+#define CPLD_HEAD_KEYWORD "Header"
+#define CPLD_NAME_KEYWORD "Entity"
+#define CPLD_INIT_KEYWORD "INITIALIZE"
+#define CPLD_REPEAT_KEYWORD "REPEAT"
+#define CPLD_END_CHAR ','
+
+/* TCK clock MAX 16MHz */
+#define TCK_DELAY (current_fmw_cpld->tck_delay)
+
+/*
+ * The instruction format of the MAX II CPLD is 10 bits
+ * For shift_ir state machine use
+ */
+#define BYPASS 0x3FF
+#define EXTEST 0xF
+#define SAMPLE 0x5
+#define IDCODE 0x6
+#define USERCODE 0x7
+#define CLAMP 0xA
+#define HIGHZ 0xB
+
+/* Following 7 instructions are IEEE 1532 instructions */
+#define ISC_ENABLE 0x2CC
+#define ISC_DISABLE 0x201
+#define ISC_PROGRAM 0x2F4
+#define ISC_ERASE 0x2F2
+#define ISC_ADDRESS_SHIFT 0x203
+#define ISC_READ 0x205
+#define ISC_NOOP 0x210
+
+/*
+ * MAX II devices support the real-time in-system programmability (ISP)
+ * feature that allows you to program the device while it is still in operation.
+ * when there is either a power cycle to the device (powering down and powering
+ * up again) or with the execution of certain ISP instructions to start the SRAM
+ * download process when realtime ISP has completed.
+ */
+#define RT_ISC_ENABLE 0x199
+#define RT_ISC_DISABLE 0x166
+
+/* Chip ID */
+#define EPM240_G 0x020A10DD
+#define EPM570_G 0x020A20DD
+#define EPM1270_G 0x020A30DD
+#define EPM2210_G 0x020A40DD
+#define EPM240_Z 0x020A50DD
+#define EPM570_Z 0x020A60DD
+
+/* The size of the output data for ID validation */
+#define VERIFY_IDCODE_SIZE 0x5
+
+/* Erasure and programmatic delay handling */
+#define ERASE_DELAY 0x1024
+#define PROGRAM_DELAY 0x5
+
+/* Chip instruction register */
+#define CPLD_INSTRUCTION_SIZE 10
+
+/*
+ * Currently, only two connectors are supported
+ * The size of the instruction register needs to be changed
+ * when more than two connectors are used
+ */
+#ifndef CPLD_MAX_CHIP
+#define CPLD_MAX_CHIP 2
+#endif
+
+typedef struct cpld_chip_id {
+ char *name;
+ uint id;
+ int addr_register_length;
+ int data_register_length;
+ int eeprom_array_length;
+ int first_blank_check_length;
+ int second_blank_check_length;
+ int first_erase_addr;
+ int second_erase_addr;
+ int third_erase_addr;
+ int verify_idcode_addr;
+} cpld_chip_id_t;
+
+static cpld_chip_id_t cpld_id_table[] = {
+ {"EPM240T100", EPM240_G, 13, 16, 4604, 3327, 511, 0x0, 0x1, 0x11, 0x89},
+ {"EPM570T144", EPM570_G, 14, 16, 8700, 3327, 511, 0x0, 0x1, 0x21, 0x111},
+ {"EPM1270F256", EPM1270_G, 15, 16, 16892, 16383, 511, 0x0, 0x1, 0x41, 0x221},
+ {"5M240Z", EPM240_Z, 13, 16, 4604, 3327, 511, 0x0, 0x1, 0x11, 0x89},
+ {"5M570Z", EPM570_Z, 14, 16, 8700, 3327, 511, 0x0, 0x1, 0x21, 0x111},
+ {NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+};
+
+static cpld_chip_id_t *chip_cpld_info = NULL;
+
+/* The following variables are used when cascading multiple chips */
+static int chip_num, current_chip_index;
+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;
+}
+
+/*
+ * firmware_upgrade_en
+ * function: Upgrade access enabling switch
+ * @flag: !0:enable 0:disable
+ */
+static int firmware_upgrade_en(int flag)
+{
+ int i;
+ int ret;
+
+ 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_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;
+ }
+ }
+ return 0;
+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 = gpio_request(current_fmw_cpld->tdi, "cpld_upgrade");
+ if (ret) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_upgrade TDI GPIO failed!\n");
+ return ret;
+ }
+ ret = gpio_request(current_fmw_cpld->tck, "cpld_upgrade");
+ if (ret) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_upgrade TCK GPIO failed!\n");
+ goto free_tdi;
+ }
+ ret = gpio_request(current_fmw_cpld->tms, "cpld_upgrade");
+ if (ret) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_upgrade TMS GPIO failed!\n");
+ goto free_tck;
+ }
+ ret = gpio_request(current_fmw_cpld->tdo, "cpld_upgrade");
+ if (ret) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Requesting cpld_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;
+ }
+
+ /* 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;
+ }
+
+ 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;
+ }
+}
+
+/*
+ * tap_test_logic_reset
+ * function: reset JTAG
+ * No matter what the original state of the controoler, it will enter
+ * Test_Logic_Reset when TMS is held high for at least five rising
+ * edges of TCK (16MHz)
+ * The controller remains in this state while TMS is high
+ */
+static void tap_test_logic_reset(void)
+{
+ int i;
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+
+ for (i = 0; i < 5; i++) {
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ }
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_run_test_idle
+ * function: A controller state between scan operations.Once entered, the controller
+ * will remain in the Run_Test/Idle state as long as TMS is held low.
+ */
+static void tap_run_test_idle(void)
+{
+ TMS_PULL_DOWN();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_select_dr_scan
+ * function :This is a temporary controller state in which all test data registers
+ * selected by the current instruction retain their previous state.
+ */
+static void tap_select_dr_scan(void)
+{
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_capture_dr
+ * function : In this controller state data may be parallel-loaded into test data
+ * register selected by the current instruction on the rising edge of TCK
+ */
+static void tap_capture_dr(void)
+{
+ TMS_PULL_DOWN();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_shift_dr
+ * function: In this controller state.the test data register connected between TDI
+ * and TDO as a result of the current instruction shifts one stage
+ * toward its serial output on each rising edge of TCK.
+ */
+static void tap_shift_dr(void)
+{
+ TMS_PULL_DOWN();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_exit1_dr
+ * function: This is a temporary controller state.
+ */
+static void tap_exit1_dr(int data)
+{
+ int j;
+ if (data) {
+ TDI_PULL_UP();
+ } else {
+ TDI_PULL_DOWN();
+ }
+
+ /* need to idle here */
+ for (j = 1; j < current_chip_index; j++) {
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ }
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_update_dr
+ * function : Some test data registers may be provided with a latched parallel output to
+ * prevent changes at the parallel out-put while data is shifted in the
+ * associated whift-register path in response to certain instructions.Data is
+ * latched onto the parallel output of these test data registers from the
+ * shift-register path on the falling edge of TCK in the Update-DR controler state.
+ */
+static void tap_update_dr(void)
+{
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_select_ir_scan
+ * function:This is a temporarily controler state in which all test data register selected
+ * by the current instruction retain their previous state.
+ */
+static void tap_select_ir_scan(void)
+{
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_capture_ir
+ * function :In this controller state the shift-register contained in the instruction
+ * register loads a pattern of fixed logic values on the rising edge of
+ * TCK.design-specific data may be loaded into shift-register stages that
+ * are not required to be set to fixed values.
+ */
+static void tap_capture_ir(void)
+{
+ TMS_PULL_DOWN();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_exit1_ir
+ * function : enter exit1 ir state. This is a temporary controller state.
+ */
+static void tap_exit1_ir(int data)
+{
+ if (data) {
+ TDI_PULL_UP();
+ } else {
+ TDI_PULL_DOWN();
+ }
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * tap_shift_ir
+ * function: In this controller state the shift-register contained in the instruction
+ * register is connected between TDI and TDO and shifts data one stage
+ * toward its serial output on each rising edge of TCK.
+ */
+static void tap_shift_ir(void)
+{
+ TMS_PULL_DOWN();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+/*
+ * The instruction shifted into the instruction register is latched onto the parallel output
+ * from the shift-register path on the falling edge of TCK in this controller state.Once the
+ * new instruction has been latched,it becomes the current instruction.
+ *
+ */
+static void tap_update_ir(void)
+{
+ TMS_PULL_UP();
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+}
+
+static void tap_send_instruction(int instruction, int ins_len)
+{
+ int i;
+ for (i = 0; i < (ins_len - 1); i++) {
+ if (instruction & 0x1) {
+ TDI_PULL_UP();
+ } else {
+ TDI_PULL_DOWN();
+ }
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ instruction = instruction >> 1;
+ }
+}
+
+static void tap_send_data(int data, int data_len)
+{
+ int i;
+ for (i = 0; i < (data_len - 1); i++) {
+ if (data & 0x1) {
+ TDI_PULL_UP();
+ } else {
+ TDI_PULL_DOWN();
+ }
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ data = data >> 1;
+ }
+}
+
+/*
+ * tap_rcv_byte
+ * function : Receive data from the device side
+ * @data : param[out] Received data */
+static void tap_rcv_byte(u8 *data)
+{
+ int i;
+ u8 rec_data = 0;
+ unsigned char tmp;
+ ndelay(TCK_DELAY);
+ for (i = 0; i < 8; i++) {
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ tmp = TDO_READ();
+ rec_data |= (tmp << i);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ }
+ *data = rec_data;
+}
+
+/*
+ * tap_idle
+ * function :Used for state machine idling
+ */
+static void tap_idle(void)
+{
+ int i;
+ for (i = 0; i < 0x100; i++) {
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+
+ /* Timely release of CPU */
+ schedule();
+ }
+}
+
+/*
+ * jtag_read_data
+ * function :Read the JTAG output data
+ * @size: param[in] buffer size
+ * @data: param[out] read data buffer
+ */
+static void jtag_read_data(u8 *buf, int size)
+{
+ int i, j;
+ /* JTAG state switching */
+ tap_run_test_idle();
+ tap_select_dr_scan();
+ tap_capture_dr();
+ tap_shift_dr();
+ for (j = current_chip_index; j < chip_num; j++) {
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+ }
+ /* Receive data from the device side */
+ for (i = 0; i < size; i++) {
+ tap_rcv_byte(&buf[i]);
+ }
+ /* JTAG state switching */
+ tap_exit1_dr(0);
+ tap_update_dr();
+ tap_run_test_idle();
+}
+
+/*
+ * jtag_send_instruction
+ * function :JTAG instruction sending interface
+ * @instruction: param[in] Instruction to be sent
+ * @ins_length: param[in] Instruction length
+ */
+static void jtag_send_instruction(int instruction, int ins_length)
+{
+ int i, j;
+ i = 1 << (ins_length - 1);
+ /* JTAG state switching */
+ tap_run_test_idle();
+ tap_select_dr_scan();
+ tap_select_ir_scan();
+ tap_capture_ir();
+ tap_shift_ir();
+
+ for (j = chip_num; j > 1; j--) {
+ if (j == current_chip_index) {
+ tap_send_instruction(instruction, ins_length + 1);
+ } else {
+ tap_send_instruction(BYPASS, ins_length + 1);
+ }
+ }
+
+ if (current_chip_index == 1) {
+ tap_send_instruction(instruction, ins_length);
+ /* Gets the highest bit of the instruction */
+ tap_exit1_ir((instruction & i) >> (ins_length - 1));
+ } else {
+ tap_send_instruction(BYPASS, ins_length);
+ /* Gets the highest bit of the instruction */
+ tap_exit1_ir((BYPASS & i) >> (ins_length - 1));
+ }
+
+ /* JTAG state switching */
+ tap_update_ir();
+ tap_run_test_idle();
+}
+
+/*
+ * jtag_send_data
+ * function :JTAG data sending interface
+ * @buf : param[in] Data that needs to be sent
+ * @data_length: param[in] Data length
+ */
+static void jtag_send_data(unsigned int buf, int data_length)
+{
+ int i;
+ i = 1 << (data_length - 1);
+
+ /* JTAG state switching */
+ tap_run_test_idle();
+ tap_select_dr_scan();
+ tap_capture_dr();
+ tap_shift_dr();
+ tap_send_data(buf, data_length);
+ /* Gets the highest bit of the instruction */
+ tap_exit1_dr((buf & i) >> (data_length - 1));
+ tap_update_dr();
+ tap_run_test_idle();
+}
+
+/*
+ * jtag_program_donebit
+ * JTAG programming end point */
+static void jtag_program_donebit(void)
+{
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x0, chip_cpld_info->addr_register_length);
+ tap_idle();
+
+ switch (chip_cpld_info->id) {
+ case EPM240_G:
+ case EPM570_G:
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x7BFF, chip_cpld_info->data_register_length);
+ tap_idle();
+ break;
+ case EPM1270_G:
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x7FFF, chip_cpld_info->data_register_length);
+ tap_idle();
+
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0xFFFF, chip_cpld_info->data_register_length);
+ tap_idle();
+
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0xFFBF, chip_cpld_info->data_register_length);
+ tap_idle();
+
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0xFFFF, chip_cpld_info->data_register_length);
+ tap_idle();
+ break;
+ default:
+ break;
+ } /* End of switch */
+}
+
+/*
+ * jtag_rt_disable
+ * JTAG Disable state machine under Real-Time ISP
+ */
+static void jtag_rt_disable(void)
+{
+ jtag_send_instruction(RT_ISC_DISABLE, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_instruction(BYPASS, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+}
+
+/*
+ * jtag_verify_idcode
+ * function :JTAG internal ID reading
+ */
+static void jtag_verify_idcode(void)
+{
+ int data, i;
+ u8 buf[2];
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(chip_cpld_info->verify_idcode_addr,
+ chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (i = 0; i < VERIFY_IDCODE_SIZE; i++) {
+ jtag_send_instruction(ISC_READ, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_read_data(buf, 2);
+
+ /* When validating the ID, the data is compared to the corresponding chip value,
+ which is retrieved from the BSDL file*/
+ data = (buf[1] << 8) | buf[0];
+ }
+}
+
+/*
+ * jtag_rt_enable
+ * Enter Real-Time ISP mode; JTAG Enable State Machine under Real-Time ISP
+ */
+static void jtag_rt_enable(void)
+{
+ jtag_send_instruction(RT_ISC_ENABLE, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+}
+
+/*
+ * jtag_erase
+ * JTAG erases the timing
+ */
+static void jtag_erase(void)
+{
+ int i;
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(chip_cpld_info->first_erase_addr,
+ chip_cpld_info->addr_register_length);
+ tap_idle();
+ jtag_send_instruction(ISC_ERASE, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ for (i = 0; i < ERASE_DELAY; i++) {
+ tap_idle();
+ tap_idle();
+ }
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(chip_cpld_info->second_erase_addr,
+ chip_cpld_info->addr_register_length);
+ tap_idle();
+ jtag_send_instruction(ISC_ERASE, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ for (i = 0; i < ERASE_DELAY; i++) {
+ tap_idle();
+ tap_idle();
+ }
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(chip_cpld_info->third_erase_addr,
+ chip_cpld_info->addr_register_length);
+ tap_idle();
+ jtag_send_instruction(ISC_ERASE, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ for (i = 0; i < ERASE_DELAY; i++) {
+ tap_idle();
+ tap_idle();
+ }
+}
+
+/*
+ * jtag_blank_check
+ * JTAG blank detection */
+static void jtag_blank_check(void)
+{
+ int j;
+ int data;
+ u8 buf[2];
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x0, chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (j = 0; j < chip_cpld_info->first_blank_check_length; j++) {
+ jtag_send_instruction(ISC_READ, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_read_data(buf, 2);
+ data = (buf[1] << 8) | buf[0];
+ }
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x1, chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (j = 0; j < chip_cpld_info->second_blank_check_length; j++) {
+ jtag_send_instruction(ISC_READ, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_read_data(buf, 2);
+ data = (buf[1] << 8) | buf[0];
+ }
+}
+
+/*
+ * jtag_verify1
+ * function :JTAG content validation
+ * @buffer : param[in] original data
+ * return value 0 validation success; -1 validation failed
+ */
+static int jtag_verify1(unsigned int *buffer)
+{
+ int j, ret = 0;
+ unsigned int data;
+ u8 buf[2];
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x0, chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (j = 0; j < chip_cpld_info->eeprom_array_length; j++) {
+ jtag_send_instruction(ISC_READ, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_read_data(buf, 2);
+ data = (buf[1] << 8) | buf[0];
+
+ if (data != buffer[j]) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("%d: %02x, %02x.\n", j, data, buffer[j]);
+ ret = -1;
+ break;
+ }
+ }
+ return ret;
+}
+
+/*
+ * jtag_read_buffer
+ * function:JTAG internal data reading
+ * @size: param[in] Read size
+ * @buffer: param[out] Pointer to read data
+ */
+static void jtag_read_buffer(unsigned int *buffer, int size)
+{
+ int j;
+ int data;
+ u8 buf[2];
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x0, chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (j = 0; j < size; j++) {
+ jtag_send_instruction(ISC_READ, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_read_data(buf, 2);
+ data = (buf[1] << 8) | buf[0];
+ buffer[j] = data;
+ }
+}
+
+/*
+ * jtag_program
+ * function:JTAG programming timing
+ * @buffer: param[in] data pointer to program
+ */
+static void jtag_program(unsigned int *buffer)
+{
+ int i, j;
+
+ jtag_send_instruction(ISC_ADDRESS_SHIFT, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+ jtag_send_data(0x0, chip_cpld_info->addr_register_length);
+ tap_idle();
+ for (j = 0; j < chip_cpld_info->eeprom_array_length; j++) {
+ jtag_send_instruction(ISC_PROGRAM, CPLD_INSTRUCTION_SIZE);
+ tap_idle();
+
+ jtag_send_data(buffer[j], chip_cpld_info->data_register_length);
+ for (i = 0; i < PROGRAM_DELAY; i++) {
+ tap_idle();
+ tap_idle();
+ }
+ }
+}
+
+/*
+ * cpld_read_id
+ * function: CPLD chip ID read
+ * @chip: param[in] chip index
+ * id : param[out] ID point */
+static void cpld_read_id(int chip, unsigned int *id)
+{
+ u8 data[sizeof(int)];
+ if (!chip_num || chip > chip_num) {
+ return;
+ }
+ current_chip_index = chip;
+ /* Send instructions */
+ jtag_send_instruction(IDCODE, CPLD_INSTRUCTION_SIZE);
+ /* Read Data */
+ jtag_read_data(data, sizeof(int));
+ *id = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
+}
+
+/*
+ * chip_num_init
+ * function:CPLD number of chips initialized */
+static void chip_num_init(void)
+{
+ unsigned int i, id;
+ unsigned char buf[sizeof(int) * CPLD_MAX_CHIP];
+ chip_num = 0;
+
+ /* JTAG state switching */
+ tap_run_test_idle();
+ tap_select_dr_scan();
+ tap_capture_dr();
+ tap_shift_dr();
+
+ for (i = 0; i < sizeof(int) * CPLD_MAX_CHIP; i++) {
+ tap_rcv_byte(&buf[i]);
+ }
+
+ /* JTAG state switching */
+ tap_exit1_dr(0);
+ tap_update_dr();
+ tap_run_test_idle();
+
+ for (i = 0; i < sizeof(int) * CPLD_MAX_CHIP; i += 4) {
+ id = (buf[i + 3] << 24) | (buf[i + 2] << 16) | (buf[i + 1] << 8) | buf[i];
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("ID: %04x\n", id);
+ if (id != 0xFFFFFFFF && id != 0) {
+ chip_num++;
+ }
+ }
+}
+
+/*
+ * cpld_reset
+ * function: reset JTAG
+ * @chip: param[in] chip index
+ */
+static void cpld_reset(int chip)
+{
+ unsigned int chip_type_id = 0;
+ int i;
+ /* JTAG enters the reset state */
+ tap_test_logic_reset();
+ /* Gets the number of chips in the CPLD */
+ chip_num_init();
+ if (!chip_num) {
+ pr_notice("There is no CPLD chip or the chip is not supported!!\r\n");
+ FIRMWARE_DRIVER_DEBUG_ERROR("chip_num == NULL.\n");
+ } else {
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("enter cpld read id.\n");
+ current_chip_index = chip;
+ /* Read chip ID */
+ cpld_read_id(current_chip_index, &chip_type_id);
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("get cpld id: 0x%x.\n", chip_type_id);
+ for (i = 0; cpld_id_table[i].name != NULL; i++) {
+ if (cpld_id_table[i].id == chip_type_id) {
+ chip_cpld_info = &cpld_id_table[i];
+ break;
+ }
+ }
+ }
+ current_chip_index = -1;
+ tap_test_logic_reset();
+}
+
+/*
+ * cpld_program
+ * function: CPLD programming interface
+ * @chip: param[in] Chip serial number/chip index
+ * @buffer: param[in] data pointer to program
+ * return value: 0 success; -1 fail
+ */
+static int cpld_program(int chip, unsigned int *buffer)
+{
+ int ret;
+ int counte;
+
+ if (!chip_num || chip > chip_num
+ || chip_cpld_info == NULL) {
+ return -1;
+ }
+ current_chip_index = chip;
+
+ /* Enter Real-Time ISP mode */
+ jtag_rt_enable();
+ /* JTAG internal ID reading */
+ jtag_verify_idcode();
+ /* JTAG erases */
+ jtag_erase();
+ /* JTAG blank detection */
+ jtag_blank_check();
+ /* JTAG programming timing */
+ jtag_program(buffer);
+
+ /* In the process of upgrade, there is a problem with reading data,
+ * which may occur in the process of reading. Some bit reading fails,
+ * but the reason is not found.
+ * Avoidance resolution: perform multiple checks */
+ for (counte = 0; counte < 4; counte++) {
+ ret = jtag_verify1(buffer);
+ if (counte > 0) {
+ pr_notice("Verify again(%d).\n", counte + 1);
+ }
+
+ if (ret == 0) {
+ break;
+ }
+ }
+ pr_notice("Write chip %d cpld success(%d).\n", chip, ret);
+ jtag_program_donebit();
+
+ /* JTAG Disable state machine under Real-Time ISP */
+ jtag_rt_disable();
+
+ return ret;
+}
+
+static void cpld_read_buffer(int chip, unsigned int *buffer, unsigned int size)
+{
+ if (!chip_num || chip > chip_num
+ || chip_cpld_info == NULL) {
+ return;
+ }
+ current_chip_index = chip;
+
+ /* Enter Real-Time ISP mode */
+ jtag_rt_enable();
+
+ /* JTAG internal ID reading */
+ jtag_verify_idcode();
+
+ /* JTAG internal data reading */
+ jtag_read_buffer(buffer, size);
+
+ jtag_rt_disable();
+
+}
+
+/*
+ * cpld_eeprom_size
+ * function:CPLD chip capacity size
+ * return value :Returns chip capacity on success, or 0 on failure
+ */
+static int cpld_eeprom_size(void)
+{
+ int ret;
+
+ if (!chip_num || chip_cpld_info == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("chip_num:%d or chip_cpld_info == NULL.\n", chip_num);
+ ret = 0;
+ } else {
+ ret = chip_cpld_info->eeprom_array_length;
+ FIRMWARE_DRIVER_DEBUG_ERROR("chip_cpld_info->eeprom_array_length = %d.\n",
+ chip_cpld_info->eeprom_array_length);
+ }
+
+ return ret;
+}
+
+/*
+ * cpld_read_name
+ * function: Gets the CPLD chip name
+ * @chip: param[in] Chip serial number/chip index
+ * return value :chip name */
+static char *cpld_read_name(int chip)
+{
+ uint chip_type_id;
+ int i;
+
+ chip_type_id = 0;
+ cpld_read_id(chip, &chip_type_id);
+ for (i = 0; cpld_id_table[i].name != NULL; i++) {
+ if (cpld_id_table[i].id == chip_type_id) {
+ return cpld_id_table[i].name;
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * 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;
+}
+
+static int cpld_str_hex_to_dec(char *str, char end_char)
+{
+ int i;
+ int result;
+
+ if (str == NULL) {
+ return FIRMWARE_FAILED;
+ }
+
+ i = 0;
+ result = 0;
+ while (str[i] != end_char) {
+ /* Check for hexadecimal characters:0123456789abcdef */
+ if (!isxdigit(str[i]) || i >= CPLD_UNIT_SZ) {
+ return FIRMWARE_FAILED;
+ }
+ /* Check for a number between 0 and 9 */
+ if (isdigit(str[i])) {
+ result = result * CPLD_HEX + str[i] - '0';
+ }
+ /* Check if the character is uppercase */
+ else if (isupper(str[i])) {
+ result = result * CPLD_HEX + str[i] - 'A' + DEC_VAL;
+ } else {
+ result = result * CPLD_HEX + str[i] - 'a' + DEC_VAL;
+ }
+
+ i++;
+ }
+
+ return result;
+}
+
+static int cpld_check_upgrade_data(char *src, int src_len, int *dst, int dst_len)
+{
+ int i, init_lcnt, tmp;
+ char *ptr;
+ int ret;
+
+ if (src == NULL || dst == NULL) {
+ return FIRMWARE_FAILED;
+ }
+ /* Pointers the ptr pointer to the data following the CPLD_INIT_KEYWORD */
+ ret = FIRMWARE_SUCCESS;
+ ptr = strstr(src, CPLD_INIT_KEYWORD);
+ if (ptr == NULL) {
+ return FIRMWARE_FAILED;
+ } else {
+ ptr += strlen(CPLD_INIT_KEYWORD);
+ while (*ptr == '(' || *ptr == '\r' || *ptr == '\n') {
+ ptr++;
+ }
+ }
+
+ /* Converts a hexadecimal string to decimal, with 4 groups of 4 bytes each */
+ i = 0;
+ init_lcnt = 0;
+ for (init_lcnt = 0; init_lcnt < CPLD_INIT_CNT; init_lcnt++) {
+ tmp = cpld_str_hex_to_dec(ptr, CPLD_END_CHAR);
+ if (tmp < 0) {
+ ret = tmp;
+ return ret;
+ }
+ /* int type is 4 bytes */
+ dst[i++] = tmp;
+ if (i >= dst_len) {
+ return FIRMWARE_SUCCESS;
+ }
+
+ ptr += CPLD_UNIT_SZ + 1;
+
+ while (*ptr == '\r' || *ptr == '\n') {
+ ptr++;
+ }
+ }
+
+ /* Point the ptr pointer to the data after CPLD_REPEAT_KEYWORD */
+ ptr = strstr(src, CPLD_REPEAT_KEYWORD);
+ if (ptr == NULL) {
+ return FIRMWARE_FAILED;
+ } else {
+ ptr += strlen(CPLD_REPEAT_KEYWORD);
+ while (*ptr == '(' || *ptr == '\r' || *ptr == '\n') {
+ ptr++;
+ }
+ }
+
+ while (1) {
+ /* Converts the 4 bytes before ',' to base 10 */
+ tmp = cpld_str_hex_to_dec(ptr, CPLD_END_CHAR);
+ if (tmp < 0) {
+ ret = tmp;
+ break;
+ }
+ dst[i++] = tmp;
+ if (i >= dst_len) {
+ return FIRMWARE_SUCCESS;
+ }
+
+ ptr += CPLD_UNIT_SZ + 1;
+
+ while (*ptr == '\r' || *ptr == '\n') {
+ ptr++;
+ }
+ }
+
+ return FIRMWARE_SUCCESS;
+}
+
+/**
+ * fmw_cpld_upg_get_chip_name
+ * function:get chip name
+ * @chain: param[in] chain
+ * @cpld: param[in] Device private data
+ * @len: param[in] chip name length
+ * @info: param[out] chip name
+ * return value: success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int fmw_cpld_upg_get_chip_name(int chain, firmware_cpld_t *cpld, char *info, int len)
+{
+ int ret;
+ char *name;
+
+ /* Check the input and output parameters */
+ if (chain < 0 || info == NULL || len <= 0) {
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to get chip name.\n");
+
+ if (cpld == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get gpio info.(chain = %d)\n", chain);
+ } else {
+ set_currrent_cpld_info(cpld);
+ }
+
+ if (chain != current_fmw_cpld->chain) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The chain num is not fit."
+ "(chain = %d, current chain = %d, current name: %s)\n",
+ chain, current_fmw_cpld->chain, current_fmw_cpld->devname);
+ }
+
+ /* Initialize GPIO and CPLD */
+ ret = cpld_upgrade_init( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error:Failed to get chip name when init upgrade.(chain = %d)\n",
+ chain);
+ return FIRMWARE_FAILED;
+ }
+
+ /* reset JTAG */
+ cpld_reset(current_fmw_cpld->chip_index);
+ /* Read chip name */
+ name = cpld_read_name(current_fmw_cpld->chip_index);
+ if (name == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to get chip name when read name.(chain %d, index %d)\n",
+ chain, current_fmw_cpld->chip_index);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ /* Release GPIO */
+ ret = cpld_upgrade_finish( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to get chip name when finish upgrade.(chain = %d)\n",
+ chain);
+ return FIRMWARE_FAILED;
+ }
+
+ strncpy(info, name, len);
+
+ return FIRMWARE_SUCCESS;
+}
+
+/**
+ * fmw_cpld_upg_program
+ * function:Upgrade CPLD(ISC file format)
+ * @chain: param[in] chain
+ * @cpld: param[in] Device private data
+ * @info: param[in] Data to be written
+ * @len: param[in] Length of data to be written
+ * return value: success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int fmw_cpld_upg_program(int chain, firmware_cpld_t *cpld, char *info, int len)
+{
+ int i;
+ int time;
+ int ret;
+ int target_len;
+ int *target_buf;
+
+ /* Check the input parameters */
+ if (chain < 0 || info == NULL || len <= 0) {
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to program chip.\n");
+
+ if (cpld == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get gpio info.(chain = %d)\n", chain);
+ } else {
+ set_currrent_cpld_info(cpld);
+ }
+
+ if (chain != current_fmw_cpld->chain) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The chain num is not fit.(chain = %d, current chain = %d)\n",
+ chain, current_fmw_cpld->chain);
+ }
+ /* Initialize GPIO and CPLD */
+ ret = cpld_upgrade_init( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to program when init upgrade.(chain = %d)\n",
+ chain);
+ return FIRMWARE_FAILED;
+ }
+
+ /* reset JTAG */
+ cpld_reset(current_fmw_cpld->chip_index);
+ /* CPLD chip capacity size */
+ target_len = cpld_eeprom_size();
+ if (target_len <= 0) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to get cpld size.(chain = %d)\n",
+ chain);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ target_buf = (int *) kzalloc(target_len * sizeof(int), GFP_KERNEL);
+ if (target_buf == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to malloc target buffer.(chain = %d)\n",
+ chain);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("cpld_check_upgrade_data start.(chain = %d, %d)\n",
+ chain, target_len);
+ /* Remove extraneous information */
+ ret = cpld_check_upgrade_data(info, len, target_buf, target_len);
+ if (ret < 0){
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to check data.(chain = %d)\n",
+ chain);
+ kfree(target_buf);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ for (i = 0; i < 16 * 8; i += 8) {
+ FIRMWARE_DRIVER_DEBUG_VERBOSE(" %x %x %x %x %x %x %x %x\n",
+ target_buf[i], target_buf[i + 1],
+ target_buf[i + 2], target_buf[i + 3],
+ target_buf[i + 4], target_buf[i + 5],
+ target_buf[i + 6], target_buf[i + 7]);
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("cpld_check_upgrade_data finish.(chain = %d)\n", chain);
+
+ /* CPLD device writing */
+ for (time = 0; time < 10; time++) {
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Start upgrade cpld: %d.(chain = %d)\n", time, chain);
+ ret = cpld_program(current_fmw_cpld->chip_index, target_buf);
+ if (ret >= 0) {
+ break;
+ }
+ }
+ if (ret < 0) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to program.(chain = %d)\n", chain);
+ kfree(target_buf);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("SUCCESS PROGRAM.\n");
+
+ /* Release GPIO */
+ ret = cpld_upgrade_finish();
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to program when finish upgrade.(chain = %d)\n",
+ chain);
+ }
+
+ kfree(target_buf);
+ return FIRMWARE_SUCCESS;
+}
+
+/**
+ * fmw_cpld_upg_program_jbi
+ * function: Upgrade CPLD(JBI file format)
+ * @chain: param[in] chain
+ * @cpld: param[in] Device private data
+ * @info: param[in] Data to be written
+ * @len: param[in] Length of data to be written
+ * return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int fmw_cpld_upg_program_jbi(int chain, firmware_cpld_t *cpld, char *info, int len)
+{
+ int time, ret;
+ int argc = 3;
+ char *argv[] = {
+ "-r",
+ "-aprogram",
+ "-ddo_real_time_isp=1"
+ };
+
+ /* Check the input parameters */
+ if (chain < 0 || info == NULL || len <= 0) {
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to program chip %d(%p,%p,%d).\n",
+ chain, cpld, info, len);
+
+ if (cpld == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get gpio info.(chain = %d)\n", chain);
+ } else {
+ set_currrent_cpld_info(cpld);
+ }
+
+ if (chain != current_fmw_cpld->chain) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The chain num is not fit.(chain = %d, current chain = %d)\n",
+ chain, current_fmw_cpld->chain);
+ }
+ /* Initialize GPIO and CPLD */
+ ret = cpld_upgrade_init( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to program when init upgrade.(chain = %d)\n",
+ chain);
+ return FIRMWARE_FAILED;
+ }
+
+ /* reset JTAG */
+ cpld_reset(current_fmw_cpld->chip_index);
+
+ for (time = 0; time < 30; time++) {
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Start upgrade cpld: %d.(chain = %d)\n", time, chain);
+ ret = jbi_main((unsigned char *) info, (unsigned long) len, argc, argv);
+ if (ret == 0) {
+ break;
+ }
+ }
+ if (ret < 0) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to program.(chain = %d)\n", chain);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("SUCCESS PROGRAM.\n");
+
+ /* Release GPIO and CPLD */
+ ret = cpld_upgrade_finish( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to program when finish upgrade.(chain = %d)\n",
+ chain);
+ }
+
+ return FIRMWARE_SUCCESS;
+}
+
+/**
+ * fmw_cpld_upg_get_version
+ * function: get version
+ * @chain: param[in] chain
+ * @cpld: param[in] Device private data
+ * @len: param[in] Data length
+ * @info: param[out] Version information buffer
+ * return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int fmw_cpld_upg_get_version(int chain, firmware_cpld_t *cpld, char *info, int len)
+{
+ int ret;
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to get version.\n");
+ if (cpld == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get gpio info.(chain = %d)\n", chain);
+ } else {
+ set_currrent_cpld_info(cpld);
+ }
+
+ if (chain != current_fmw_cpld->chain) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The chain num is not fit.(chain = %d, current chain = %d)\n",
+ chain, current_fmw_cpld->chain);
+ }
+
+ /* CPLD device can't get version */
+ if (function_fmw_cpld.get_version != NULL) {
+ ret = function_fmw_cpld.get_version(chain, info, len);
+ if (ret < 0) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed get version in chain: %d.\n", chain);
+ return FIRMWARE_FAILED;
+ }
+
+ return FIRMWARE_SUCCESS;
+ } else {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The get_version is NULL in chain: %d.\n", chain);
+ }
+
+ return FIRMWARE_FAILED;
+}
+
+/**
+ * fmw_cpld_upg_get_chip_info
+ * function: Get chip content
+ * @chain: param[in] chain
+ * @cpld: param[in] Device private data
+ * @len: param[in] Data length
+ * @info: param[out] Read Data Buffer
+ * return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int fmw_cpld_upg_get_chip_info(int chain, firmware_cpld_t *cpld, void *info, int len)
+{
+ int i;
+ int ret;
+ int target_len;
+ int *target_buf;
+
+ /* Check input and output parameters */
+ if (chain < 0 || info == NULL || len <= 0) {
+ return FIRMWARE_FAILED;
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to read chip.\n");
+
+ if (cpld == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to get gpio info.(chain = %d)\n", chain);
+ } else {
+ set_currrent_cpld_info(cpld);
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Cpld driver to read chip: %s.\n",current_fmw_cpld->devname);
+ if (chain != current_fmw_cpld->chain) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("The chain num is not fit.(chain = %d, current chain = %d)\n",
+ chain, current_fmw_cpld->chain);
+ }
+
+ /* Initialize GPIO and CPLD */
+ ret = cpld_upgrade_init( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to program when init upgrade.(chain = %d)\n",
+ chain);
+ return FIRMWARE_FAILED;
+ }
+
+ /* reset JTAG*/
+ cpld_reset(current_fmw_cpld->chip_index);
+ /* CPLD chip capacity size */
+ target_len = cpld_eeprom_size();
+ if (target_len <= 0) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to get cpld size.(chain = %d)\n",
+ chain);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+
+ target_buf = (int *) kzalloc(target_len * sizeof(int), GFP_KERNEL);
+ if (target_buf == NULL) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Error: Failed to malloc target buffer.(chain = %d)\n",
+ chain);
+ cpld_upgrade_finish( );
+ return FIRMWARE_FAILED;
+ }
+ /* Read chip */
+ cpld_read_buffer(current_fmw_cpld->chip_index, target_buf, target_len);
+
+ for (i = 0; i < 16 * 8; i += 8) {
+ FIRMWARE_DRIVER_DEBUG_VERBOSE(" %x %x %x %x %x %x %x %x\n",
+ target_buf[i], target_buf[i + 1],
+ target_buf[i + 2], target_buf[i + 3],
+ target_buf[i + 4], target_buf[i + 5],
+ target_buf[i + 6], target_buf[i + 7]);
+ }
+
+ FIRMWARE_DRIVER_DEBUG_VERBOSE("Success Read.\n");
+
+ /* Release GPIO and CPLD */
+ ret = cpld_upgrade_finish( );
+ if (ret != FIRMWARE_SUCCESS) {
+ FIRMWARE_DRIVER_DEBUG_ERROR("Failed to program when finish upgrade.(chain = %d)\n",
+ chain);
+ }
+
+ if (copy_to_user(info, target_buf, (len > target_len) ? target_len : len)) {
+ kfree(target_buf);
+ return FIRMWARE_FAILED;
+ }
+
+ kfree(target_buf);
+ return FIRMWARE_SUCCESS;
+}
+
+/**
+ * jbi_jtag_io_
+ * function: JBI GPIO operation
+ * @tms: param[in] TMS signal level
+ * @tdi: param[in] TDI signal level
+ * @read_tdo: param[in] Whether to read the level of the TDO
+ * return value : tdo
+ */
+int __attribute__ ((weak)) jbi_jtag_io_(int tms, int tdi, int read_tdo)
+{
+ int tdo = 0;
+
+ if (tms) {
+ TMS_PULL_UP();
+ } else {
+ TMS_PULL_DOWN();
+ }
+
+ if (tdi) {
+ TDI_PULL_UP();
+ } else {
+ TDI_PULL_DOWN();
+ }
+
+ TCK_PULL_UP();
+ ndelay(TCK_DELAY);
+
+ if (read_tdo) {
+ tdo = TDO_READ();
+ }
+
+ TCK_PULL_DOWN();
+ ndelay(TCK_DELAY);
+
+ return tdo;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware.h
new file mode 100644
index 0000000000..3a6ab117df
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware.h
@@ -0,0 +1,82 @@
+#ifndef __FIRMWARE_H__
+#define __FIRMWARE_H__
+
+#include
+#include
+
+#include
+
+/* 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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware_cpld.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware_cpld.h
new file mode 100644
index 0000000000..ef69655a4b
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/firmware_cpld.h
@@ -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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/jbi.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/jbi.h
new file mode 100644
index 0000000000..865c8d3521
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/include/jbi.h
@@ -0,0 +1,15 @@
+#ifndef __JBI_H__
+#define __JBI_H__
+
+#include
+
+/* 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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.c
new file mode 100644
index 0000000000..064d0ae50e
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.c
@@ -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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.h
new file mode 100644
index 0000000000..4dacdcd5d7
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbicomp.h
@@ -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 */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiexprt.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiexprt.h
new file mode 100644
index 0000000000..ef4699dd6d
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiexprt.h
@@ -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 */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.c
new file mode 100644
index 0000000000..f013100eec
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.c
@@ -0,0 +1,1679 @@
+/****************************************************************************/
+/* */
+/* Module: jbijtag.c */
+/* */
+/* Copyright (C) Altera Corporation 1998-2001 */
+/* */
+/* Description: Contains JTAG interface functions */
+/* */
+/* Revisions: 2.2 updated state transition paths */
+/* 2.0 added multi-page scan code for 16-bit PORT */
+/* */
+/****************************************************************************/
+
+#include "jbiport.h"
+#include "jbiexprt.h"
+#include "jbicomp.h"
+#include "jbijtag.h"
+
+#define NULL 0
+
+char *jbi_workspace = NULL;
+long jbi_workspace_size = 0L;
+
+/****************************************************************************/
+/* */
+/* Enumerated Types */
+/* */
+/****************************************************************************/
+
+/* maximum JTAG IR and DR lengths (in bits) */
+#define JBIC_MAX_JTAG_IR_PREAMBLE 256
+#define JBIC_MAX_JTAG_IR_POSTAMBLE 256
+#define JBIC_MAX_JTAG_IR_LENGTH 512
+#define JBIC_MAX_JTAG_DR_PREAMBLE 1024
+#define JBIC_MAX_JTAG_DR_POSTAMBLE 1024
+#define JBIC_MAX_JTAG_DR_LENGTH 2048
+
+/*
+* Global variable to store the current JTAG state
+*/
+JBIE_JTAG_STATE jbi_jtag_state = JBI_ILLEGAL_JTAG_STATE;
+
+/*
+* Store current stop-state for DR and IR scan commands
+*/
+JBIE_JTAG_STATE jbi_drstop_state = IDLE;
+JBIE_JTAG_STATE jbi_irstop_state = IDLE;
+
+/*
+* Store current padding values
+*/
+unsigned int jbi_dr_preamble = 0;
+unsigned int jbi_dr_postamble = 0;
+unsigned int jbi_ir_preamble = 0;
+unsigned int jbi_ir_postamble = 0;
+unsigned int jbi_dr_length = 0;
+unsigned int jbi_ir_length = 0;
+unsigned char *jbi_dr_preamble_data = NULL;
+unsigned char *jbi_dr_postamble_data = NULL;
+unsigned char *jbi_ir_preamble_data = NULL;
+unsigned char *jbi_ir_postamble_data = NULL;
+unsigned char *jbi_dr_buffer = NULL;
+unsigned char *jbi_ir_buffer = NULL;
+
+/*
+* This structure shows, for each JTAG state, which state is reached after
+* a single TCK clock cycle with TMS high or TMS low, respectively. This
+* describes all possible state transitions in the JTAG state machine.
+*/
+struct JBIS_JTAG_MACHINE
+{
+ JBIE_JTAG_STATE tms_high;
+ JBIE_JTAG_STATE tms_low;
+} jbi_jtag_state_transitions[] =
+{
+/* RESET */ { RESET, IDLE },
+/* IDLE */ { DRSELECT, IDLE },
+/* DRSELECT */ { IRSELECT, DRCAPTURE },
+/* DRCAPTURE */ { DREXIT1, DRSHIFT },
+/* DRSHIFT */ { DREXIT1, DRSHIFT },
+/* DREXIT1 */ { DRUPDATE, DRPAUSE },
+/* DRPAUSE */ { DREXIT2, DRPAUSE },
+/* DREXIT2 */ { DRUPDATE, DRSHIFT },
+/* DRUPDATE */ { DRSELECT, IDLE },
+/* IRSELECT */ { RESET, IRCAPTURE },
+/* IRCAPTURE */ { IREXIT1, IRSHIFT },
+/* IRSHIFT */ { IREXIT1, IRSHIFT },
+/* IREXIT1 */ { IRUPDATE, IRPAUSE },
+/* IRPAUSE */ { IREXIT2, IRPAUSE },
+/* IREXIT2 */ { IRUPDATE, IRSHIFT },
+/* IRUPDATE */ { DRSELECT, IDLE }
+};
+
+/*
+* This table contains the TMS value to be used to take the NEXT STEP on
+* the path to the desired state. The array index is the current state,
+* and the bit position is the desired endstate. To find out which state
+* is used as the intermediate state, look up the TMS value in the
+* jbi_jtag_state_transitions[] table.
+*/
+unsigned short jbi_jtag_path_map[16] =
+{
+/* RST RTI SDRS CDR SDR E1DR PDR E2DR */
+ 0x0001, 0xFFFD, 0xFE01, 0xFFE7, 0xFFEF, 0xFF0F, 0xFFBF, 0xFFFF,
+/* UDR SIRS CIR SIR E1IR PIR E2IR UIR */
+ 0xFEFD, 0x0001, 0xF3FF, 0xF7FF, 0x87FF, 0xDFFF, 0xFFFF, 0x7FFD
+};
+
+/*
+* Flag bits for jbi_jtag_io() function
+*/
+#define TMS_HIGH 1
+#define TMS_LOW 0
+#define TDI_HIGH 1
+#define TDI_LOW 0
+#define READ_TDO 1
+#define IGNORE_TDO 0
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_init_jtag()
+
+/* */
+/****************************************************************************/
+{
+ /* initial JTAG state is unknown */
+ jbi_jtag_state = JBI_ILLEGAL_JTAG_STATE;
+
+ /* initialize global variables to default state */
+ jbi_drstop_state = IDLE;
+ jbi_irstop_state = IDLE;
+ jbi_dr_preamble = 0;
+ jbi_dr_postamble = 0;
+ jbi_ir_preamble = 0;
+ jbi_ir_postamble = 0;
+ jbi_dr_length = 0;
+ jbi_ir_length = 0;
+
+ if (jbi_workspace != NULL)
+ {
+ jbi_dr_preamble_data = (unsigned char *) jbi_workspace;
+ jbi_dr_postamble_data = &jbi_dr_preamble_data[JBIC_MAX_JTAG_DR_PREAMBLE / 8];
+ jbi_ir_preamble_data = &jbi_dr_postamble_data[JBIC_MAX_JTAG_DR_POSTAMBLE / 8];
+ jbi_ir_postamble_data = &jbi_ir_preamble_data[JBIC_MAX_JTAG_IR_PREAMBLE / 8];
+ jbi_dr_buffer = &jbi_ir_postamble_data[JBIC_MAX_JTAG_IR_POSTAMBLE / 8];
+ jbi_ir_buffer = &jbi_dr_buffer[JBIC_MAX_JTAG_DR_LENGTH / 8];
+ }
+ else
+ {
+ jbi_dr_preamble_data = NULL;
+ jbi_dr_postamble_data = NULL;
+ jbi_ir_preamble_data = NULL;
+ jbi_ir_postamble_data = NULL;
+ jbi_dr_buffer = NULL;
+ jbi_ir_buffer = NULL;
+ }
+
+ return (JBIC_SUCCESS);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_drstop_state
+(
+ JBIE_JTAG_STATE state
+)
+
+/* */
+/****************************************************************************/
+{
+ jbi_drstop_state = state;
+
+ return (JBIC_SUCCESS);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_irstop_state
+(
+ JBIE_JTAG_STATE state
+)
+
+/* */
+/****************************************************************************/
+{
+ jbi_irstop_state = state;
+
+ return (JBIC_SUCCESS);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_dr_preamble
+(
+ unsigned int count,
+ unsigned int start_index,
+ unsigned char *preamble_data
+)
+
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned int i;
+ unsigned int j;
+
+ if (jbi_workspace != NULL)
+ {
+ if (count > JBIC_MAX_JTAG_DR_PREAMBLE)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_preamble = count;
+ }
+ }
+ else
+ {
+ if (count > jbi_dr_preamble)
+ {
+ jbi_free(jbi_dr_preamble_data);
+ jbi_dr_preamble_data = (unsigned char *) jbi_malloc((count + 7) >> 3);
+
+ if (jbi_dr_preamble_data == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_preamble = count;
+ }
+ }
+ else
+ {
+ jbi_dr_preamble = count;
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ j = i + start_index;
+
+ if (preamble_data == NULL)
+ {
+ jbi_dr_preamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ if (preamble_data[j >> 3] & (1 << (j & 7)))
+ {
+ jbi_dr_preamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ jbi_dr_preamble_data[i >> 3] &=
+ ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_ir_preamble
+(
+ unsigned int count,
+ unsigned int start_index,
+ unsigned char *preamble_data
+)
+
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned int i;
+ unsigned int j;
+
+ if (jbi_workspace != NULL)
+ {
+ if (count > JBIC_MAX_JTAG_IR_PREAMBLE)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_preamble = count;
+ }
+ }
+ else
+ {
+ if (count > jbi_ir_preamble)
+ {
+ jbi_free(jbi_ir_preamble_data);
+ jbi_ir_preamble_data = (unsigned char *) jbi_malloc((count + 7) >> 3);
+
+ if (jbi_ir_preamble_data == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_preamble = count;
+ }
+ }
+ else
+ {
+ jbi_ir_preamble = count;
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ j = i + start_index;
+
+ if (preamble_data == NULL)
+ {
+ jbi_ir_preamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ if (preamble_data[j >> 3] & (1 << (j & 7)))
+ {
+ jbi_ir_preamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ jbi_ir_preamble_data[i >> 3] &=
+ ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_dr_postamble
+(
+ unsigned int count,
+ unsigned int start_index,
+ unsigned char *postamble_data
+)
+
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned int i;
+ unsigned int j;
+
+ if (jbi_workspace != NULL)
+ {
+ if (count > JBIC_MAX_JTAG_DR_POSTAMBLE)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_postamble = count;
+ }
+ }
+ else
+ {
+ if (count > jbi_dr_postamble)
+ {
+ jbi_free(jbi_dr_postamble_data);
+ jbi_dr_postamble_data = (unsigned char *) jbi_malloc((count + 7) >> 3);
+
+ if (jbi_dr_postamble_data == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_postamble = count;
+ }
+ }
+ else
+ {
+ jbi_dr_postamble = count;
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ j = i + start_index;
+
+ if (postamble_data == NULL)
+ {
+ jbi_dr_postamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ if (postamble_data[j >> 3] & (1 << (j & 7)))
+ {
+ jbi_dr_postamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ jbi_dr_postamble_data[i >> 3] &=
+ ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_set_ir_postamble
+(
+ unsigned int count,
+ unsigned int start_index,
+ unsigned char *postamble_data
+)
+
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned int i;
+ unsigned int j;
+
+ if (jbi_workspace != NULL)
+ {
+ if (count > JBIC_MAX_JTAG_IR_POSTAMBLE)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_postamble = count;
+ }
+ }
+ else
+ {
+ if (count > jbi_ir_postamble)
+ {
+ jbi_free(jbi_ir_postamble_data);
+ jbi_ir_postamble_data = (unsigned char *) jbi_malloc((count + 7) >> 3);
+
+ if (jbi_ir_postamble_data == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_postamble = count;
+ }
+ }
+ else
+ {
+ jbi_ir_postamble = count;
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ for (i = 0; i < count; ++i)
+ {
+ j = i + start_index;
+
+ if (postamble_data == NULL)
+ {
+ jbi_ir_postamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ if (postamble_data[j >> 3] & (1 << (j & 7)))
+ {
+ jbi_ir_postamble_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ jbi_ir_postamble_data[i >> 3] &=
+ ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+void jbi_jtag_reset_idle(void)
+
+/* */
+/****************************************************************************/
+{
+ int i;
+
+ /*
+ * Go to Test Logic Reset (no matter what the starting state may be)
+ */
+ for (i = 0; i < 5; ++i)
+ {
+ jbi_jtag_io(TMS_HIGH, TDI_LOW, IGNORE_TDO);
+ }
+
+ /*
+ * Now step to Run Test / Idle
+ */
+ jbi_jtag_io(TMS_LOW, TDI_LOW, IGNORE_TDO);
+
+ jbi_jtag_state = IDLE;
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_goto_jtag_state
+(
+ JBIE_JTAG_STATE state
+)
+
+/* */
+/****************************************************************************/
+{
+ int tms;
+ int count = 0;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned int tmp_state;
+
+ if (jbi_jtag_state == JBI_ILLEGAL_JTAG_STATE)
+ {
+ /* initialize JTAG chain to known state */
+ jbi_jtag_reset_idle();
+ }
+
+ if (jbi_jtag_state == state)
+ {
+ /*
+ * We are already in the desired state. If it is a stable state,
+ * loop here. Otherwise do nothing (no clock cycles).
+ */
+ if ((state == IDLE) ||
+ (state == DRSHIFT) ||
+ (state == DRPAUSE) ||
+ (state == IRSHIFT) ||
+ (state == IRPAUSE))
+ {
+ jbi_jtag_io(TMS_LOW, TDI_LOW, IGNORE_TDO);
+ }
+ else if (state == RESET)
+ {
+ jbi_jtag_io(TMS_HIGH, TDI_LOW, IGNORE_TDO);
+ }
+ }
+ else
+ {
+ while ((jbi_jtag_state != state) && (count < 9))
+ {
+ /*
+ * Get TMS value to take a step toward desired state
+ */
+ if (state < 0) {
+ tmp_state = 0;
+ } else {
+ tmp_state = state;
+ }
+ tms = (jbi_jtag_path_map[jbi_jtag_state] & (1 << tmp_state)) ?
+ TMS_HIGH : TMS_LOW;
+
+ /*
+ * Take a step
+ */
+ jbi_jtag_io(tms, TDI_LOW, IGNORE_TDO);
+
+ if (tms)
+ {
+ jbi_jtag_state =
+ jbi_jtag_state_transitions[jbi_jtag_state].tms_high;
+ }
+ else
+ {
+ jbi_jtag_state =
+ jbi_jtag_state_transitions[jbi_jtag_state].tms_low;
+ }
+
+ ++count;
+ }
+ }
+
+ if (jbi_jtag_state != state)
+ {
+ status = JBIC_INTERNAL_ERROR;
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_do_wait_cycles
+(
+ long cycles,
+ JBIE_JTAG_STATE wait_state
+)
+
+/* */
+/* Description: Causes JTAG hardware to loop in the specified stable */
+/* state for the specified number of TCK clock cycles. */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ int tms;
+ long count;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+
+ if (jbi_jtag_state != wait_state)
+ {
+ status = jbi_goto_jtag_state(wait_state);
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Set TMS high to loop in RESET state
+ * Set TMS low to loop in any other stable state
+ */
+ tms = (wait_state == RESET) ? TMS_HIGH : TMS_LOW;
+
+ for (count = 0L; count < cycles; count++)
+ {
+ jbi_jtag_io(tms, TDI_LOW, IGNORE_TDO);
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_do_wait_microseconds
+(
+ long microseconds,
+ JBIE_JTAG_STATE wait_state
+)
+
+/* */
+/* Description: Causes JTAG hardware to sit in the specified stable */
+/* state for the specified duration of real time. If */
+/* no JTAG operations have been performed yet, then only */
+/* a delay is performed. This permits the WAIT USECS */
+/* statement to be used in VECTOR programs without causing */
+/* any JTAG operations. */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+
+ if ((jbi_jtag_state != JBI_ILLEGAL_JTAG_STATE) &&
+ (jbi_jtag_state != wait_state))
+ {
+ status = jbi_goto_jtag_state(wait_state);
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Wait for specified time interval
+ */
+ jbi_delay(microseconds);
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+void jbi_jtag_concatenate_data
+(
+ unsigned char *buffer,
+ unsigned char *preamble_data,
+ unsigned int preamble_count,
+ unsigned char *target_data,
+ unsigned long start_index,
+ unsigned int target_count,
+ unsigned char *postamble_data,
+ unsigned int postamble_count
+)
+
+/* */
+/* Description: Copies preamble data, target data, and postamble data */
+/* into one buffer for IR or DR scans. */
+/* */
+/* Returns: nothing */
+/* */
+/****************************************************************************/
+{
+ unsigned long i;
+ unsigned long j;
+ unsigned long k;
+
+ for (i = 0L; i < preamble_count; ++i)
+ {
+ if (preamble_data[i >> 3L] & (1L << (i & 7L)))
+ {
+ buffer[i >> 3L] |= (1L << (i & 7L));
+ }
+ else
+ {
+ buffer[i >> 3L] &= ~(unsigned int) (1L << (i & 7L));
+ }
+ }
+
+ j = start_index;
+ k = preamble_count + target_count;
+ for (; i < k; ++i, ++j)
+ {
+ if (target_data[j >> 3L] & (1L << (j & 7L)))
+ {
+ buffer[i >> 3L] |= (1L << (i & 7L));
+ }
+ else
+ {
+ buffer[i >> 3L] &= ~(unsigned int) (1L << (i & 7L));
+ }
+ }
+
+ j = 0L;
+ k = preamble_count + target_count + postamble_count;
+ for (; i < k; ++i, ++j)
+ {
+ if (postamble_data[j >> 3L] & (1L << (j & 7L)))
+ {
+ buffer[i >> 3L] |= (1L << (i & 7L));
+ }
+ else
+ {
+ buffer[i >> 3L] &= ~(unsigned int) (1L << (i & 7L));
+ }
+ }
+}
+
+int jbi_jtag_drscan
+(
+ int start_state,
+ int count,
+ unsigned char *tdi,
+ unsigned char *tdo
+)
+{
+ int i = 0;
+ int tdo_bit = 0;
+ int status = 1;
+
+ /*
+ * First go to DRSHIFT state
+ */
+ switch (start_state)
+ {
+ case 0: /* IDLE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(0, 0, 0); /* DRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* DRSHIFT */
+ break;
+
+ case 1: /* DRPAUSE */
+ jbi_jtag_io(1, 0, 0); /* DREXIT2 */
+ jbi_jtag_io(1, 0, 0); /* DRUPDATE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(0, 0, 0); /* DRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* DRSHIFT */
+ break;
+
+ case 2: /* IRPAUSE */
+ jbi_jtag_io(1, 0, 0); /* IREXIT2 */
+ jbi_jtag_io(1, 0, 0); /* IRUPDATE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(0, 0, 0); /* DRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* DRSHIFT */
+ break;
+
+ default:
+ status = 0;
+ }
+
+ if (status)
+ {
+ /* loop in the SHIFT-DR state */
+ for (i = 0; i < count; i++)
+ {
+ tdo_bit = jbi_jtag_io(
+ (i == count - 1),
+ tdi[i >> 3] & (1 << (i & 7)),
+ (tdo != NULL));
+
+ if (tdo != NULL)
+ {
+ if (tdo_bit)
+ {
+ tdo[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ tdo[i >> 3] &= ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+
+ jbi_jtag_io(0, 0, 0); /* DRPAUSE */
+ }
+
+ return (status);
+}
+
+int jbi_jtag_irscan
+(
+ int start_state,
+ int count,
+ unsigned char *tdi,
+ unsigned char *tdo
+)
+{
+ int i = 0;
+ int tdo_bit = 0;
+ int status = 1;
+
+ /*
+ * First go to IRSHIFT state
+ */
+ switch (start_state)
+ {
+ case 0: /* IDLE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(1, 0, 0); /* IRSELECT */
+ jbi_jtag_io(0, 0, 0); /* IRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* IRSHIFT */
+ break;
+
+ case 1: /* DRPAUSE */
+ jbi_jtag_io(1, 0, 0); /* DREXIT2 */
+ jbi_jtag_io(1, 0, 0); /* DRUPDATE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(1, 0, 0); /* IRSELECT */
+ jbi_jtag_io(0, 0, 0); /* IRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* IRSHIFT */
+ break;
+
+ case 2: /* IRPAUSE */
+ jbi_jtag_io(1, 0, 0); /* IREXIT2 */
+ jbi_jtag_io(1, 0, 0); /* IRUPDATE */
+ jbi_jtag_io(1, 0, 0); /* DRSELECT */
+ jbi_jtag_io(1, 0, 0); /* IRSELECT */
+ jbi_jtag_io(0, 0, 0); /* IRCAPTURE */
+ jbi_jtag_io(0, 0, 0); /* IRSHIFT */
+ break;
+
+ default:
+ status = 0;
+ }
+
+ if (status)
+ {
+ /* loop in the SHIFT-IR state */
+ for (i = 0; i < count; i++)
+ {
+ tdo_bit = jbi_jtag_io(
+ (i == count - 1),
+ tdi[i >> 3] & (1 << (i & 7)),
+ (tdo != NULL));
+
+ if (tdo != NULL)
+ {
+ if (tdo_bit)
+ {
+ tdo[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ tdo[i >> 3] &= ~(unsigned int) (1 << (i & 7));
+ }
+ }
+ }
+
+ jbi_jtag_io(0, 0, 0); /* IRPAUSE */
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+void jbi_jtag_extract_target_data
+(
+ unsigned char *buffer,
+ unsigned char *target_data,
+ unsigned int start_index,
+ unsigned int preamble_count,
+ unsigned int target_count
+)
+
+/* */
+/* Description: Copies target data from scan buffer, filtering out */
+/* preamble and postamble data. */
+/* */
+/* Returns: nothing */
+/* */
+/****************************************************************************/
+{
+ unsigned int i;
+ unsigned int j;
+ unsigned int k;
+
+ j = preamble_count;
+ k = start_index + target_count;
+ for (i = start_index; i < k; ++i, ++j)
+ {
+ if (buffer[j >> 3] & (1 << (j & 7)))
+ {
+ target_data[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ target_data[i >> 3] &= ~(unsigned int) (1 << (i & 7));
+ }
+ }
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_do_irscan
+(
+ unsigned int count,
+ unsigned char *tdi_data,
+ unsigned int start_index
+)
+
+/* */
+/* Description: Shifts data into instruction register */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ int start_code = 0;
+ unsigned int alloc_chars = 0;
+ unsigned int shift_count = jbi_ir_preamble + count + jbi_ir_postamble;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
+
+ switch (jbi_jtag_state)
+ {
+ case JBI_ILLEGAL_JTAG_STATE:
+ case RESET:
+ case IDLE:
+ start_code = 0;
+ start_state = IDLE;
+ break;
+
+ case DRSELECT:
+ case DRCAPTURE:
+ case DRSHIFT:
+ case DREXIT1:
+ case DRPAUSE:
+ case DREXIT2:
+ case DRUPDATE:
+ start_code = 1;
+ start_state = DRPAUSE;
+ break;
+
+ case IRSELECT:
+ case IRCAPTURE:
+ case IRSHIFT:
+ case IREXIT1:
+ case IRPAUSE:
+ case IREXIT2:
+ case IRUPDATE:
+ start_code = 2;
+ start_state = IRPAUSE;
+ break;
+
+ default:
+ status = JBIC_INTERNAL_ERROR;
+ break;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_jtag_state != start_state)
+ {
+ status = jbi_goto_jtag_state(start_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_workspace != NULL)
+ {
+ if (shift_count > JBIC_MAX_JTAG_IR_LENGTH)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ }
+ else if (shift_count > jbi_ir_length)
+ {
+ alloc_chars = (shift_count + 7) >> 3;
+ jbi_free(jbi_ir_buffer);
+ jbi_ir_buffer = (unsigned char *) jbi_malloc(alloc_chars);
+
+ if (jbi_ir_buffer == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_length = alloc_chars * 8;
+ }
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Copy preamble data, IR data, and postamble data into a buffer
+ */
+ jbi_jtag_concatenate_data
+ (
+ jbi_ir_buffer,
+ jbi_ir_preamble_data,
+ jbi_ir_preamble,
+ tdi_data,
+ start_index,
+ count,
+ jbi_ir_postamble_data,
+ jbi_ir_postamble
+ );
+
+ /*
+ * Do the IRSCAN
+ */
+ jbi_jtag_irscan
+ (
+ start_code,
+ shift_count,
+ jbi_ir_buffer,
+ NULL
+ );
+
+ /* jbi_jtag_irscan() always ends in IRPAUSE state */
+ jbi_jtag_state = IRPAUSE;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_irstop_state != IRPAUSE)
+ {
+ status = jbi_goto_jtag_state(jbi_irstop_state);
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+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
+)
+
+/* */
+/* Description: Shifts data into instruction register, capturing output */
+/* data */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ int start_code = 0;
+ unsigned int alloc_chars = 0;
+ unsigned int shift_count = jbi_ir_preamble + count + jbi_ir_postamble;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
+
+ switch (jbi_jtag_state)
+ {
+ case JBI_ILLEGAL_JTAG_STATE:
+ case RESET:
+ case IDLE:
+ start_code = 0;
+ start_state = IDLE;
+ break;
+
+ case DRSELECT:
+ case DRCAPTURE:
+ case DRSHIFT:
+ case DREXIT1:
+ case DRPAUSE:
+ case DREXIT2:
+ case DRUPDATE:
+ start_code = 1;
+ start_state = DRPAUSE;
+ break;
+
+ case IRSELECT:
+ case IRCAPTURE:
+ case IRSHIFT:
+ case IREXIT1:
+ case IRPAUSE:
+ case IREXIT2:
+ case IRUPDATE:
+ start_code = 2;
+ start_state = IRPAUSE;
+ break;
+
+ default:
+ status = JBIC_INTERNAL_ERROR;
+ break;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_jtag_state != start_state)
+ {
+ status = jbi_goto_jtag_state(start_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_workspace != NULL)
+ {
+ if (shift_count > JBIC_MAX_JTAG_IR_LENGTH)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ }
+ else if (shift_count > jbi_ir_length)
+ {
+ alloc_chars = (shift_count + 7) >> 3;
+ jbi_free(jbi_ir_buffer);
+ jbi_ir_buffer = (unsigned char *) jbi_malloc(alloc_chars);
+
+ if (jbi_ir_buffer == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_ir_length = alloc_chars * 8;
+ }
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Copy preamble data, IR data, and postamble data into a buffer
+ */
+ jbi_jtag_concatenate_data
+ (
+ jbi_ir_buffer,
+ jbi_ir_preamble_data,
+ jbi_ir_preamble,
+ in_data,
+ in_index,
+ count,
+ jbi_ir_postamble_data,
+ jbi_ir_postamble
+ );
+
+ /*
+ * Do the IRSCAN
+ */
+ jbi_jtag_irscan
+ (
+ start_code,
+ shift_count,
+ jbi_ir_buffer,
+ jbi_ir_buffer
+ );
+
+ /* jbi_jtag_irscan() always ends in IRPAUSE state */
+ jbi_jtag_state = IRPAUSE;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_irstop_state != IRPAUSE)
+ {
+ status = jbi_goto_jtag_state(jbi_irstop_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Now extract the returned data from the buffer
+ */
+ jbi_jtag_extract_target_data
+ (
+ jbi_ir_buffer,
+ out_data,
+ out_index,
+ jbi_ir_preamble,
+ count
+ );
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_do_drscan
+(
+ unsigned int count,
+ unsigned char *tdi_data,
+ unsigned long start_index
+)
+
+/* */
+/* Description: Shifts data into data register (ignoring output data) */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ int start_code = 0;
+ unsigned int alloc_chars = 0;
+ unsigned int shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
+
+ switch (jbi_jtag_state)
+ {
+ case JBI_ILLEGAL_JTAG_STATE:
+ case RESET:
+ case IDLE:
+ start_code = 0;
+ start_state = IDLE;
+ break;
+
+ case DRSELECT:
+ case DRCAPTURE:
+ case DRSHIFT:
+ case DREXIT1:
+ case DRPAUSE:
+ case DREXIT2:
+ case DRUPDATE:
+ start_code = 1;
+ start_state = DRPAUSE;
+ break;
+
+ case IRSELECT:
+ case IRCAPTURE:
+ case IRSHIFT:
+ case IREXIT1:
+ case IRPAUSE:
+ case IREXIT2:
+ case IRUPDATE:
+ start_code = 2;
+ start_state = IRPAUSE;
+ break;
+
+ default:
+ status = JBIC_INTERNAL_ERROR;
+ break;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_jtag_state != start_state)
+ {
+ status = jbi_goto_jtag_state(start_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_workspace != NULL)
+ {
+ if (shift_count > JBIC_MAX_JTAG_DR_LENGTH)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ }
+ else if (shift_count > jbi_dr_length)
+ {
+ alloc_chars = (shift_count + 7) >> 3;
+ jbi_free(jbi_dr_buffer);
+ jbi_dr_buffer = (unsigned char *) jbi_malloc(alloc_chars);
+
+ if (jbi_dr_buffer == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_length = alloc_chars * 8;
+ }
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Copy preamble data, DR data, and postamble data into a buffer
+ */
+ jbi_jtag_concatenate_data
+ (
+ jbi_dr_buffer,
+ jbi_dr_preamble_data,
+ jbi_dr_preamble,
+ tdi_data,
+ start_index,
+ count,
+ jbi_dr_postamble_data,
+ jbi_dr_postamble
+ );
+
+ /*
+ * Do the DRSCAN
+ */
+ jbi_jtag_drscan
+ (
+ start_code,
+ shift_count,
+ jbi_dr_buffer,
+ NULL
+ );
+
+ /* jbi_jtag_drscan() always ends in DRPAUSE state */
+ jbi_jtag_state = DRPAUSE;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_drstop_state != DRPAUSE)
+ {
+ status = jbi_goto_jtag_state(jbi_drstop_state);
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+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
+)
+
+/* */
+/* Description: Shifts data into data register, capturing output data */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ int start_code = 0;
+ unsigned int alloc_chars = 0;
+ unsigned int shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ JBIE_JTAG_STATE start_state = JBI_ILLEGAL_JTAG_STATE;
+
+ switch (jbi_jtag_state)
+ {
+ case JBI_ILLEGAL_JTAG_STATE:
+ case RESET:
+ case IDLE:
+ start_code = 0;
+ start_state = IDLE;
+ break;
+
+ case DRSELECT:
+ case DRCAPTURE:
+ case DRSHIFT:
+ case DREXIT1:
+ case DRPAUSE:
+ case DREXIT2:
+ case DRUPDATE:
+ start_code = 1;
+ start_state = DRPAUSE;
+ break;
+
+ case IRSELECT:
+ case IRCAPTURE:
+ case IRSHIFT:
+ case IREXIT1:
+ case IRPAUSE:
+ case IREXIT2:
+ case IRUPDATE:
+ start_code = 2;
+ start_state = IRPAUSE;
+ break;
+
+ default:
+ status = JBIC_INTERNAL_ERROR;
+ break;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_jtag_state != start_state)
+ {
+ status = jbi_goto_jtag_state(start_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_workspace != NULL)
+ {
+ if (shift_count > JBIC_MAX_JTAG_DR_LENGTH)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ }
+ else if (shift_count > jbi_dr_length)
+ {
+ alloc_chars = (shift_count + 7) >> 3;
+ jbi_free(jbi_dr_buffer);
+ jbi_dr_buffer = (unsigned char *) jbi_malloc(alloc_chars);
+
+ if (jbi_dr_buffer == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ jbi_dr_length = alloc_chars * 8;
+ }
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Copy preamble data, DR data, and postamble data into a buffer
+ */
+ jbi_jtag_concatenate_data
+ (
+ jbi_dr_buffer,
+ jbi_dr_preamble_data,
+ jbi_dr_preamble,
+ in_data,
+ in_index,
+ count,
+ jbi_dr_postamble_data,
+ jbi_dr_postamble
+ );
+
+ /*
+ * Do the DRSCAN
+ */
+ jbi_jtag_drscan
+ (
+ start_code,
+ shift_count,
+ jbi_dr_buffer,
+ jbi_dr_buffer
+ );
+
+ /* jbi_jtag_drscan() always ends in DRPAUSE state */
+ jbi_jtag_state = DRPAUSE;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (jbi_drstop_state != DRPAUSE)
+ {
+ status = jbi_goto_jtag_state(jbi_drstop_state);
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Now extract the returned data from the buffer
+ */
+ jbi_jtag_extract_target_data
+ (
+ jbi_dr_buffer,
+ out_data,
+ out_index,
+ jbi_dr_preamble,
+ count
+ );
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+void jbi_free_jtag_padding_buffers(int reset_jtag)
+
+/* */
+/* Description: Frees memory allocated for JTAG IR and DR buffers */
+/* */
+/* Returns: nothing */
+/* */
+/****************************************************************************/
+{
+ /*
+ * If the JTAG interface was used, reset it to TLR
+ */
+ if (reset_jtag && (jbi_jtag_state != JBI_ILLEGAL_JTAG_STATE))
+ {
+ jbi_jtag_reset_idle();
+ }
+
+ if (jbi_workspace == NULL)
+ {
+ if (jbi_dr_preamble_data != NULL)
+ {
+ jbi_free(jbi_dr_preamble_data);
+ jbi_dr_preamble_data = NULL;
+ }
+
+ if (jbi_dr_postamble_data != NULL)
+ {
+ jbi_free(jbi_dr_postamble_data);
+ jbi_dr_postamble_data = NULL;
+ }
+
+ if (jbi_dr_buffer != NULL)
+ {
+ jbi_free(jbi_dr_buffer);
+ jbi_dr_buffer = NULL;
+ }
+
+ if (jbi_ir_preamble_data != NULL)
+ {
+ jbi_free(jbi_ir_preamble_data);
+ jbi_ir_preamble_data = NULL;
+ }
+
+ if (jbi_ir_postamble_data != NULL)
+ {
+ jbi_free(jbi_ir_postamble_data);
+ jbi_ir_postamble_data = NULL;
+ }
+
+ if (jbi_ir_buffer != NULL)
+ {
+ jbi_free(jbi_ir_buffer);
+ jbi_ir_buffer = NULL;
+ }
+ }
+}
+
+#if PORT==DOS
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_do_drscan_multi_page
+(
+ unsigned int variable_id,
+ unsigned long count,
+ unsigned long start_index,
+ int version
+)
+
+/* */
+/* Description: Shifts data into data register (ignoring output data) */
+/* Scan data comes from compressed Boolean array. */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned long shift_count = jbi_dr_preamble + count + jbi_dr_postamble;
+ unsigned long i;
+ unsigned long j;
+ unsigned long k;
+ unsigned int bi;
+
+ if (status == JBIC_SUCCESS)
+ {
+ status = jbi_goto_jtag_state(DRSHIFT);
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ /*
+ * Get preamble data, DR data, and postamble data one bit at a time
+ * and immediately scan it into the JTAG chain
+ */
+
+ for (i = 0L; i < jbi_dr_preamble; ++i)
+ {
+ jbi_jtag_io((i == shift_count - 1),
+ (int) (jbi_dr_preamble_data[i >> 3L] & (1L << (i & 7L))), 0);
+ }
+
+ j = start_index;
+ k = jbi_dr_preamble + count;
+
+ jbi_uncompress_page(variable_id, (unsigned int) (j >> 16L), version);
+
+ for (; i < k; ++i, ++j)
+ {
+ bi = (unsigned int) (j & 0x0000ffffL);
+
+ /* check for page boundary - load next page if necessary */
+ if (bi == 0)
+ {
+ jbi_uncompress_page(variable_id, (unsigned int) (j >> 16L), version);
+ }
+
+ jbi_jtag_io((i == shift_count - 1),
+ (int) (jbi_aca_out_buffer[bi >> 3] & (1 << (bi & 7))), 0);
+ }
+
+ j = 0L;
+ k = jbi_dr_preamble + count + jbi_dr_postamble;
+ for (; i < k; ++i, ++j)
+ {
+ jbi_jtag_io((i == shift_count - 1),
+ (int) (jbi_dr_postamble_data[j >> 3L] & (1L << (j & 7L))), 0);
+ }
+
+ jbi_jtag_io(0, 0, 0); /* DRPAUSE */
+
+ /* jbi_jtag_drscan() always ends in DRPAUSE state */
+ jbi_jtag_state = DRPAUSE;
+
+ if (jbi_drstop_state != DRPAUSE)
+ {
+ status = jbi_goto_jtag_state(jbi_drstop_state);
+ }
+ }
+
+ return (status);
+}
+
+#endif
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.h
new file mode 100644
index 0000000000..fab2dac026
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbijtag.h
@@ -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 */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbimain.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbimain.c
new file mode 100644
index 0000000000..b8cab48570
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbimain.c
@@ -0,0 +1,3362 @@
+/****************************************************************************/
+/* */
+/* Module: jbimain.c */
+/* */
+/* Copyright (C) Altera Corporation 1998-2001 */
+/* */
+/* Description: Jam STAPL ByteCode Player (Interpreter) */
+/* */
+/* Revisions: 2.2 fixed /W4 warnings */
+/* 2.0 added support for STAPL ByteCode format */
+/* */
+/****************************************************************************/
+
+#include "jbiport.h"
+#include "jbiexprt.h"
+#include "jbijtag.h"
+#include "jbicomp.h"
+#include "jbistub.h"
+
+/****************************************************************************/
+/* */
+/* MACROS */
+/* */
+/****************************************************************************/
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#define JBI_STACK_SIZE 128
+
+#define JBIC_MESSAGE_LENGTH 1024
+
+/*
+* This macro checks if enough parameters are available on the stack. The
+* argument is the number of parameters needed.
+*/
+#define IF_CHECK_STACK(x) \
+ if (stack_ptr < (int) (x)) \
+ { \
+ status = JBIC_STACK_OVERFLOW; \
+ } \
+ else
+
+/*
+* This macro checks if a code address is inside the code section
+*/
+#define CHECK_PC \
+ if ((pc < code_section) || (pc >= debug_section)) \
+ { \
+ status = JBIC_BOUNDS_ERROR; \
+ }
+
+/****************************************************************************/
+/* */
+/* GLOBAL VARIABLES */
+/* */
+/****************************************************************************/
+
+#if PORT==DOS
+/*
+* jbi_program is a global pointer used by macros GET_BYTE, GET_WORD, and
+* GET_DWORD to read data from the JBC file
+*/
+PROGRAM_PTR jbi_program;
+#endif
+
+/****************************************************************************/
+/* */
+/* UTILITY FUNCTIONS */
+/* */
+/****************************************************************************/
+
+int jbi_strlen(char *string)
+{
+ int len = 0;
+
+ while (string[len] != '\0') ++len;
+
+ return (len);
+}
+
+long jbi_atol(char *buffer)
+{
+ long result = 0L;
+ int index = 0;
+
+ while ((buffer[index] >= '0') && (buffer[index] <= '9'))
+ {
+ result = (result * 10) + (buffer[index] - '0');
+ ++index;
+ }
+
+ return (result);
+}
+
+void jbi_ltoa(char *buffer, long number)
+{
+ int index = 0;
+ int rev_index = 0;
+ char reverse[32];
+
+ if (number < 0L)
+ {
+ buffer[index++] = '-';
+ number = 0 - number;
+ }
+ else if (number == 0)
+ {
+ buffer[index++] = '0';
+ }
+
+ while (number != 0)
+ {
+ reverse[rev_index++] = (char) ((number % 10) + '0');
+ number /= 10;
+ }
+
+ while (rev_index > 0)
+ {
+ buffer[index++] = reverse[--rev_index];
+ }
+
+ buffer[index] = '\0';
+}
+
+char jbi_toupper(char ch)
+{
+ return ((char) (((ch >= 'a') && (ch <= 'z')) ? (ch + 'A' - 'a') : ch));
+}
+
+int jbi_stricmp(char *left, char *right)
+{
+ int result = 0;
+ char l, r;
+
+ do
+ {
+ l = jbi_toupper(*left);
+ r = jbi_toupper(*right);
+ result = l - r;
+ ++left;
+ ++right;
+ }
+ while ((result == 0) && (l != '\0') && (r != '\0'));
+
+ return (result);
+}
+
+void jbi_strncpy(char *left, char *right, int count)
+{
+ char ch;
+
+ do
+ {
+ *left = *right;
+ ch = *right;
+ ++left;
+ ++right;
+ --count;
+ }
+ while ((ch != '\0') && (count != 0));
+}
+
+void jbi_make_dword(unsigned char *buf, unsigned long num)
+{
+ buf[0] = (unsigned char) num;
+ buf[1] = (unsigned char) (num >> 8L);
+ buf[2] = (unsigned char) (num >> 16L);
+ buf[3] = (unsigned char) (num >> 24L);
+}
+
+unsigned long jbi_get_dword(unsigned char *buf)
+{
+ return
+ (((unsigned long) buf[0]) |
+ (((unsigned long) buf[1]) << 8L) |
+ (((unsigned long) buf[2]) << 16L) |
+ (((unsigned long) buf[3]) << 24L));
+}
+
+/****************************************************************************/
+/* */
+
+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
+)
+
+/* */
+/* Description: */
+/* */
+/* Returns: */
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned long first_word = 0L;
+ unsigned long action_table = 0L;
+ unsigned long proc_table = 0L;
+ unsigned long string_table = 0L;
+ unsigned long symbol_table = 0L;
+ unsigned long data_section = 0L;
+ unsigned long code_section = 0L;
+ unsigned long debug_section = 0L;
+ unsigned long action_count = 0L;
+ unsigned long proc_count = 0L;
+ unsigned long symbol_count = 0L;
+ /*char message_buffer[JBIC_MESSAGE_LENGTH + 1];*/
+ char *message_buffer;
+ addr_t *variables = NULL;
+ long *variable_size = NULL;
+ char *attributes = NULL;
+ unsigned char *proc_attributes = NULL;
+ unsigned long pc;
+ unsigned long opcode_address;
+ unsigned long args[3];
+ unsigned int opcode;
+ unsigned long name_id;
+ addr_t stack[JBI_STACK_SIZE] = {0};
+ unsigned char charbuf[4];
+ long long_temp;
+ unsigned int variable_id;
+ unsigned char *charptr_temp;
+ unsigned char *charptr_temp2;
+ long *longptr_temp;
+ int version = 0;
+ int delta = 0;
+ int stack_ptr = 0;
+ unsigned int arg_count;
+ int done = 0;
+ int bad_opcode = 0;
+ unsigned int count;
+ unsigned int index;
+ unsigned int index2;
+ long long_count;
+ long long_index;
+ long long_index2;
+ unsigned int i;
+ unsigned int j;
+ unsigned long uncompressed_size, uncompressed_result;
+ unsigned int offset;
+ unsigned long value;
+ int current_proc = 0;
+ char *equal_ptr;
+ int length;
+ int reverse;
+
+ unsigned long debug_cnt = 0;
+
+#if PORT==DOS
+ char name[33];
+#else
+ char *name;
+#endif
+
+ jbi_workspace = workspace;
+ jbi_workspace_size = workspace_size;
+
+#if PORT==DOS
+ jbi_program = program;
+#endif
+
+ /* Resolve compilation warnings: the frame size of 1664 bytes is larger than 1024 bytes */
+ message_buffer = (char *) kzalloc(JBIC_MESSAGE_LENGTH + 1, GFP_KERNEL);
+ if (message_buffer == NULL) {
+ jbi_dbg(DEBUG_DETAIL, "Memory not enough jbi_execute \n");
+ return JBIC_OUT_OF_MEMORY;
+ }
+
+ /*
+ * Read header information
+ */
+ if (program_size > 52L)
+ {
+ first_word = GET_DWORD(0);
+ version = (int) (first_word & 1L);
+ *format_version = version + 1;
+ delta = version * 8;
+
+ action_table = GET_DWORD(4);
+ proc_table = GET_DWORD(8);
+ string_table = GET_DWORD(4 + delta);
+ symbol_table = GET_DWORD(16 + delta);
+ data_section = GET_DWORD(20 + delta);
+ code_section = GET_DWORD(24 + delta);
+ debug_section = GET_DWORD(28 + delta);
+ action_count = GET_DWORD(40 + delta);
+ proc_count = GET_DWORD(44 + delta);
+ symbol_count = GET_DWORD(48 + (2 * delta));
+
+ jbi_dbg(DEBUG_DETAIL, "version: %d\n", version);
+ jbi_dbg(DEBUG_DETAIL, "delta: %d\n", delta);
+ jbi_dbg(DEBUG_DETAIL, "action_table: 0x%08lx\n", action_table);
+ jbi_dbg(DEBUG_DETAIL, "proc_table: 0x%08lx\n", proc_table);
+ jbi_dbg(DEBUG_DETAIL, "string_table: 0x%08lx\n", string_table);
+ jbi_dbg(DEBUG_DETAIL, "symbol_table: 0x%08lx\n", symbol_table);
+ jbi_dbg(DEBUG_DETAIL, "data_section: 0x%08lx\n", data_section);
+ jbi_dbg(DEBUG_DETAIL, "code_section: 0x%08lx\n", code_section);
+ jbi_dbg(DEBUG_DETAIL, "debug_section: 0x%08lx\n", debug_section);
+ jbi_dbg(DEBUG_DETAIL, "action_count: 0x%08lx\n", action_count);
+ jbi_dbg(DEBUG_DETAIL, "proc_count: 0x%08lx\n", proc_count);
+ jbi_dbg(DEBUG_DETAIL, "symbol_count: 0x%08lx\n", symbol_count);
+ jbi_dbg(DEBUG_DETAIL, "\n");
+ }
+
+ if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L))
+ {
+ jbi_dbg(DEBUG_ERR, "first_word 0x%lx\n", first_word);
+ done = 1;
+ status = JBIC_IO_ERROR;
+ }
+
+ if ((status == JBIC_SUCCESS) && (symbol_count > 0))
+ {
+ variables = (addr_t *) jbi_malloc(
+ (unsigned int) symbol_count * sizeof(long));
+
+ if (variables == NULL) status = JBIC_OUT_OF_MEMORY;
+
+ if (status == JBIC_SUCCESS)
+ {
+ variable_size = (long *) jbi_malloc(
+ (unsigned int) symbol_count * sizeof(long));
+
+ if (variable_size == NULL) status = JBIC_OUT_OF_MEMORY;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ attributes = (char *) jbi_malloc((unsigned int) symbol_count);
+
+ if (attributes == NULL) status = JBIC_OUT_OF_MEMORY;
+ }
+
+ if ((status == JBIC_SUCCESS) && (version > 0))
+ {
+ proc_attributes = (unsigned char *) jbi_malloc((unsigned int) proc_count);
+
+ if (proc_attributes == NULL) status = JBIC_OUT_OF_MEMORY;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ delta = version * 2;
+
+ for (i = 0; i < (unsigned int) symbol_count; ++i)
+ {
+ offset = (unsigned int) (symbol_table + ((11 + delta) * i));
+
+ value = GET_DWORD(offset + 3 + delta);
+
+ attributes[i] = GET_BYTE(offset);
+
+ /* use bit 7 of attribute byte to indicate that this buffer */
+ /* was dynamically allocated and should be freed later */
+ attributes[i] &= 0x7f;
+
+ variable_size[i] = GET_DWORD(offset + 7 + delta);
+
+ jbi_dbg(DEBUG_NOISY, "symbol %03d: 0x%02x,0x%08lx,0x%08lx\n",
+ i, attributes[i], value, variable_size[i]);
+
+ /*
+ * Attribute bits:
+ * bit 0: 0 = read-only, 1 = read-write
+ * bit 1: 0 = not compressed, 1 = compressed
+ * bit 2: 0 = not initialized, 1 = initialized
+ * bit 3: 0 = scalar, 1 = array
+ * bit 4: 0 = Boolean, 1 = integer
+ * bit 5: 0 = declared variable,
+ * 1 = compiler created temporary variable
+ */
+
+ if ((attributes[i] & 0x0c) == 0x04)
+ {
+ /* initialized scalar variable */
+ variables[i] = value;
+ }
+ else if ((attributes[i] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+#if PORT==DOS
+ /* for DOS port, get the size but do not uncompress */
+ long_index = data_section + value;
+ uncompressed_size =
+ (((unsigned long) GET_BYTE(long_index)) |
+ (((unsigned long) GET_BYTE(long_index + 1L)) << 8L) |
+ (((unsigned long) GET_BYTE(long_index + 2L)) << 16L) |
+ (((unsigned long) GET_BYTE(long_index + 3L)) << 24L));
+ variable_size[i] = uncompressed_size;
+#else
+ uncompressed_size = jbi_get_dword(
+ &program[data_section + value]);
+
+ /* allocate a buffer for the uncompressed data */
+ variables[i] = (addr_t) jbi_malloc(uncompressed_size);
+
+ if (variables[i] == (addr_t) 0L)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ /* set flag so buffer will be freed later */
+ attributes[i] |= 0x80;
+
+ /* uncompress the data */
+ uncompressed_result =
+ jbi_uncompress(
+ &program[data_section + value],
+ variable_size[i],
+ (unsigned char *) variables[i],
+ uncompressed_size,
+ version);
+ if (uncompressed_result != uncompressed_size)
+ {
+ /* decompression failed */
+ jbi_dbg(DEBUG_ERR, "uncompress fail(0x%lx,0x%lx,0x%lx)(0x%lx)\n",
+ variable_size[i], uncompressed_result, uncompressed_size, value);
+ status = JBIC_IO_ERROR;
+ }
+ else
+ {
+ variable_size[i] = uncompressed_size * 8L;
+ }
+ }
+#endif
+ }
+ else if ((attributes[i] & 0x1e) == 0x0c)
+ {
+ /* initialized Boolean array */
+#if PORT==DOS
+ /* flag attributes so that memory is freed */
+ attributes[i] |= 0x80;
+
+ if (variable_size[i] > 0)
+ {
+ unsigned int size = (unsigned int)
+ ((variable_size[i] + 7L) / 8L);
+
+ variables[i] = (long) jbi_malloc(size);
+
+ if (variables[i] == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ unsigned char *p = (unsigned char *) variables[i];
+ /* copy array values into buffer */
+ for (j = 0; j < size; ++j)
+ {
+ p[j] = GET_BYTE(data_section + value + j);
+ }
+ }
+ }
+ else
+ {
+ variables[i] = 0;
+ }
+#else
+ variables[i] = value + data_section + (addr_t) program;
+#endif
+ }
+ else if ((attributes[i] & 0x1c) == 0x1c)
+ {
+ /* initialized integer array */
+ variables[i] = value + data_section;
+ }
+ else if ((attributes[i] & 0x0c) == 0x08)
+ {
+ /* uninitialized array */
+
+ /* flag attributes so that memory is freed */
+ attributes[i] |= 0x80;
+
+ if (variable_size[i] > 0)
+ {
+ unsigned int size;
+
+ if (attributes[i] & 0x10)
+ {
+ /* integer array */
+ size = (unsigned int)
+ (variable_size[i] * sizeof(long));
+ }
+ else
+ {
+ /* Boolean array */
+ size = (unsigned int)
+ ((variable_size[i] + 7L) / 8L);
+ }
+
+ variables[i] = (addr_t) jbi_malloc(size);
+
+ if (variables[i] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ /* zero out memory */
+ for (j = 0; j < size; ++j)
+ {
+ ((unsigned char *)(variables[i]))[j] = 0;
+ }
+ }
+ }
+ else
+ {
+ variables[i] = 0;
+ }
+ }
+ else
+ {
+ variables[i] = 0;
+ }
+
+ jbi_dbg(DEBUG_NOISY, " variables: 0x%08lx,0x%016llx\n",
+ variable_size[i], (long long) variables[i]);
+ }
+ }
+
+ jbi_dbg(DEBUG_NOISY, "\n");
+ }
+
+ /*
+ * Initialize variables listed in init_list
+ */
+ if ((status == JBIC_SUCCESS) && (init_list != NULL) && (version == 0))
+ {
+ delta = version * 2;
+ count = 0;
+ while (init_list[count] != NULL)
+ {
+ equal_ptr = init_list[count];
+ length = 0;
+ while ((*equal_ptr != '=') && (*equal_ptr != '\0'))
+ {
+ ++equal_ptr;
+ ++length;
+ }
+ if (*equal_ptr == '=')
+ {
+ ++equal_ptr;
+ value = jbi_atol(equal_ptr);
+ jbi_strncpy(message_buffer, init_list[count], length);
+ message_buffer[length] = '\0';
+ for (i = 0; i < (unsigned int) symbol_count; ++i)
+ {
+ offset = (unsigned int) (symbol_table + ((11 + delta) * i));
+ name_id = (version == 0) ? GET_WORD(offset + 1) :
+ GET_DWORD(offset + 1);
+#if PORT==DOS
+ for (j = 0; j < 32; ++j)
+ {
+ name[j] = GET_BYTE(string_table + name_id + j);
+ }
+ name[32] = '\0';
+#else
+ name = (char *) &program[string_table + name_id];
+#endif
+
+ if (jbi_stricmp(message_buffer, name) == 0)
+ {
+ variables[i] = value;
+ }
+
+ jbi_dbg(DEBUG_NOISY, "init_list %03d: 0x%08lx,%s,0x%016llx\n",
+ i, name_id, name, (long long) variables[i]);
+ }
+ }
+
+ ++count;
+ }
+
+ jbi_dbg(DEBUG_NOISY, "\n");
+ }
+
+ if (status != JBIC_SUCCESS) done = 1;
+
+ jbi_init_jtag();
+
+ pc = code_section;
+ message_buffer[0] = '\0';
+
+ /*
+ * For JBC version 2, we will execute the procedures corresponding to
+ * the selected ACTION
+ */
+ if (version > 0)
+ {
+ if (action == NULL)
+ {
+ status = JBIC_ACTION_NOT_FOUND;
+ done = 1;
+ }
+ else
+ {
+ int action_found = 0;
+
+ for (i = 0; (i < action_count) && !action_found; ++i)
+ {
+ name_id = GET_DWORD(action_table + (12 * i));
+
+#if PORT==DOS
+ for (j = 0; j < 32; ++j)
+ {
+ name[j] = GET_BYTE(string_table + name_id + j);
+ }
+ name[32] = '\0';
+#else
+ name = (char *) &program[string_table + name_id];
+#endif
+
+ if (jbi_stricmp(action, name) == 0)
+ {
+ action_found = 1;
+ current_proc = (int) GET_DWORD(action_table + (12 * i) + 8);
+ }
+
+ jbi_dbg(DEBUG_NOISY, "action %03d: 0x%08lx,%s, %d,%d\n",
+ i, name_id, name, action_found, current_proc);
+ }
+
+ if (!action_found)
+ {
+ status = JBIC_ACTION_NOT_FOUND;
+ done = 1;
+ }
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ int first_time = 1;
+ i = current_proc;
+ while ((i != 0) || first_time)
+ {
+ first_time = 0;
+ /* check procedure attribute byte */
+ proc_attributes[i] = (unsigned char)
+ (GET_BYTE(proc_table + (13 * i) + 8) & 0x03);
+
+ jbi_dbg(DEBUG_NOISY, " proc_attributes %03d: 0x%02x\n",
+ i, proc_attributes[i]);
+
+ if (proc_attributes[i] != 0)
+ {
+ /*
+ * BIT0 - OPTIONAL
+ * BIT1 - RECOMMENDED
+ * BIT6 - FORCED OFF
+ * BIT7 - FORCED ON
+ */
+ if (init_list != NULL)
+ {
+ name_id = GET_DWORD(proc_table + (13 * i));
+#if PORT==DOS
+ for (j = 0; j < 32; ++j)
+ {
+ name[j] = GET_BYTE(string_table + name_id + j);
+ }
+ name[32] = '\0';
+#else
+ name = (char *) &program[string_table + name_id];
+#endif
+
+ jbi_dbg(DEBUG_NOISY, " init_list %03d: 0x%08lx,%s\n",
+ i, name_id, name);
+
+ count = 0;
+ while (init_list[count] != NULL)
+ {
+ equal_ptr = init_list[count];
+ length = 0;
+ while ((*equal_ptr != '=') && (*equal_ptr != '\0'))
+ {
+ ++equal_ptr;
+ ++length;
+ }
+ if (*equal_ptr == '=')
+ {
+ ++equal_ptr;
+ jbi_strncpy(message_buffer, init_list[count], length);
+ message_buffer[length] = '\0';
+
+ if (jbi_stricmp(message_buffer, name) == 0)
+ {
+ if (jbi_atol(equal_ptr) == 0)
+ {
+ proc_attributes[i] |= 0x40;
+ }
+ else
+ {
+ proc_attributes[i] |= 0x80;
+ }
+ }
+ }
+
+ jbi_dbg(DEBUG_NOISY, " proc_attributes %03d: 0x%02x\n",
+ i, proc_attributes[i]);
+
+ ++count;
+ }
+ }
+ }
+
+ i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
+ }
+
+ /*
+ * Set current_proc to the first procedure to be executed
+ */
+ i = current_proc;
+ while ((i != 0) &&
+ ((proc_attributes[i] == 1) ||
+ ((proc_attributes[i] & 0xc0) == 0x40)))
+ {
+ i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
+ }
+
+ if ((i != 0) || ((i == 0) && (current_proc == 0) &&
+ ((proc_attributes[0] != 1) &&
+ ((proc_attributes[0] & 0xc0) != 0x40))))
+ {
+ current_proc = i;
+ pc = code_section + GET_DWORD(proc_table + (13 * i) + 9);
+ CHECK_PC;
+ }
+ else
+ {
+ /* there are no procedures to execute! */
+ done = 1;
+ }
+ }
+
+ jbi_dbg(DEBUG_NOISY, "\n");
+ }
+
+ message_buffer[0] = '\0';
+
+ jbi_dbg(DEBUG_NOISY, "excute pc: 0x%lx,%d\n", pc, current_proc);
+ while (!done)
+ {
+ opcode = (unsigned int) (GET_BYTE(pc) & 0xff);
+ debug_cnt++;
+ jbi_dbg(DEBUG_NOISY, "op: 0x%02x(%03d:0x%08lx,%08lx)",
+ opcode, stack_ptr, pc, debug_cnt);
+ opcode_address = pc;
+ ++pc;
+
+ arg_count = (opcode >> 6) & 3;
+ jbi_dbg(DEBUG_NOISY, " - %u:", arg_count);
+ for (i = 0; i < arg_count; ++i)
+ {
+ args[i] = GET_DWORD(pc);
+ jbi_dbg(DEBUG_NOISY, " 0x%08lx", args[i]);
+ pc += 4;
+ }
+ jbi_dbg(DEBUG_NOISY, "\n");
+
+ switch (opcode)
+ {
+ case 0x00: /* NOP */
+ /* do nothing */
+ break;
+
+ case 0x01: /* DUP */
+ IF_CHECK_STACK(1)
+ {
+ stack[stack_ptr] = stack[stack_ptr - 1];
+ ++stack_ptr;
+ }
+ break;
+
+ case 0x02: /* SWP */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[stack_ptr - 2];
+ stack[stack_ptr - 2] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+ break;
+
+ case 0x03: /* ADD */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] += stack[stack_ptr];
+ }
+ break;
+
+ case 0x04: /* SUB */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] -= stack[stack_ptr];
+ }
+ break;
+
+ case 0x05: /* MULT */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] *= stack[stack_ptr];
+ }
+ break;
+
+ case 0x06: /* DIV */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] /= stack[stack_ptr];
+ }
+ break;
+
+ case 0x07: /* MOD */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] %= stack[stack_ptr];
+ }
+ break;
+
+ case 0x08: /* SHL */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] <<= stack[stack_ptr];
+ }
+ break;
+
+ case 0x09: /* SHR */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] >>= stack[stack_ptr];
+ }
+ break;
+
+ case 0x0A: /* NOT */
+ IF_CHECK_STACK(1)
+ {
+ stack[stack_ptr - 1] ^= (-1L);
+ }
+ break;
+
+ case 0x0B: /* AND */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] &= stack[stack_ptr];
+ }
+ break;
+
+ case 0x0C: /* OR */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] |= stack[stack_ptr];
+ }
+ break;
+
+ case 0x0D: /* XOR */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] ^= stack[stack_ptr];
+ }
+ break;
+
+ case 0x0E: /* INV */
+ IF_CHECK_STACK(1)
+ {
+ stack[stack_ptr - 1] = stack[stack_ptr - 1] ? 0L : 1L;
+ }
+ break;
+
+ case 0x0F: /* GT */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] =
+ (stack[stack_ptr - 1] > stack[stack_ptr]) ? 1L : 0L;
+ }
+ break;
+
+ case 0x10: /* LT */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] =
+ (stack[stack_ptr - 1] < stack[stack_ptr]) ? 1L : 0L;
+ }
+ break;
+
+ case 0x11: /* RET */
+ if ((version > 0) && (stack_ptr == 0))
+ {
+ /*
+ * We completed one of the main procedures of an ACTION.
+ * Find the next procedure to be executed and jump to it.
+ * If there are no more procedures, then EXIT.
+ */
+ i = (unsigned int) GET_DWORD(proc_table + (13 * current_proc) + 4);
+ while ((i != 0) &&
+ ((proc_attributes[i] == 1) ||
+ ((proc_attributes[i] & 0xc0) == 0x40)))
+ {
+ i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
+ }
+
+ if (i == 0)
+ {
+ /* there are no procedures to execute! */
+ done = 1;
+ *exit_code = 0; /* success */
+ }
+ else
+ {
+ current_proc = i;
+ pc = code_section + GET_DWORD(proc_table + (13 * i) + 9);
+ CHECK_PC;
+ }
+ }
+ else IF_CHECK_STACK(1)
+ {
+ pc = stack[--stack_ptr] + code_section;
+ CHECK_PC;
+ if (pc == code_section)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ }
+ break;
+
+ case 0x12: /* CMPS */
+ /*
+ * Array short compare
+ * ...stack 0 is source 1 value
+ * ...stack 1 is source 2 value
+ * ...stack 2 is mask value
+ * ...stack 3 is count
+ */
+ IF_CHECK_STACK(4)
+ {
+ long a = stack[--stack_ptr];
+ long b = stack[--stack_ptr];
+ long_temp = stack[--stack_ptr];
+ count = (unsigned int) stack[stack_ptr - 1];
+
+ if ((count < 1) || (count > 32))
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ long_temp &= ((-1L) >> (32 - count));
+
+ stack[stack_ptr - 1] =
+ ((a & long_temp) == (b & long_temp)) ? 1L : 0L;
+ }
+ }
+ break;
+
+ case 0x13: /* PINT */
+ /*
+ * PRINT add integer
+ * ...stack 0 is integer value
+ */
+ IF_CHECK_STACK(1)
+ {
+ jbi_ltoa(&message_buffer[jbi_strlen(message_buffer)],
+ stack[--stack_ptr]);
+ }
+ break;
+
+ case 0x14: /* PRNT */
+ /*
+ * PRINT finish
+ */
+ jbi_message(message_buffer);
+ message_buffer[0] = '\0';
+ break;
+
+ case 0x15: /* DSS */
+ /*
+ * DRSCAN short
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_do_drscan(count, charbuf, 0);
+ }
+ break;
+
+ case 0x16: /* DSSC */
+ /*
+ * DRSCAN short with capture
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[--stack_ptr];
+ count = (unsigned int) stack[stack_ptr - 1];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_swap_dr(count, charbuf, 0, charbuf, 0);
+ stack[stack_ptr - 1] = jbi_get_dword(charbuf);
+ }
+ break;
+
+ case 0x17: /* ISS */
+ /*
+ * IRSCAN short
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_do_irscan(count, charbuf, 0);
+ }
+ break;
+
+ case 0x18: /* ISSC */
+ /*
+ * IRSCAN short with capture
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[--stack_ptr];
+ count = (unsigned int) stack[stack_ptr - 1];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_swap_ir(count, charbuf, 0, charbuf, 0);
+ stack[stack_ptr - 1] = jbi_get_dword(charbuf);
+ }
+ break;
+
+ case 0x19: /* VSS */
+ /*
+ * VECTOR short
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x1A: /* VSSC */
+ /*
+ * VECTOR short with capture
+ * ...stack 0 is scan data
+ * ...stack 1 is count
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x1B: /* VMPF */
+ /*
+ * VMAP finish
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x1C: /* DPR */
+ IF_CHECK_STACK(1)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ status = jbi_set_dr_preamble(count, 0, NULL);
+ }
+ break;
+
+ case 0x1D: /* DPRL */
+ /*
+ * DRPRE with literal data
+ * ...stack 0 is count
+ * ...stack 1 is literal data
+ */
+ IF_CHECK_STACK(2)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ long_temp = stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_set_dr_preamble(count, 0, charbuf);
+ }
+ break;
+
+ case 0x1E: /* DPO */
+ /*
+ * DRPOST
+ * ...stack 0 is count
+ */
+ IF_CHECK_STACK(1)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ status = jbi_set_dr_postamble(count, 0, NULL);
+ }
+ break;
+
+ case 0x1F: /* DPOL */
+ /*
+ * DRPOST with literal data
+ * ...stack 0 is count
+ * ...stack 1 is literal data
+ */
+ IF_CHECK_STACK(2)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ long_temp = stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_set_dr_postamble(count, 0, charbuf);
+ }
+ break;
+
+ case 0x20: /* IPR */
+ IF_CHECK_STACK(1)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ status = jbi_set_ir_preamble(count, 0, NULL);
+ }
+ break;
+
+ case 0x21: /* IPRL */
+ /*
+ * IRPRE with literal data
+ * ...stack 0 is count
+ * ...stack 1 is literal data
+ */
+ IF_CHECK_STACK(2)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ long_temp = stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_set_ir_preamble(count, 0, charbuf);
+ }
+ break;
+
+ case 0x22: /* IPO */
+ /*
+ * IRPOST
+ * ...stack 0 is count
+ */
+ IF_CHECK_STACK(1)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ status = jbi_set_ir_postamble(count, 0, NULL);
+ }
+ break;
+
+ case 0x23: /* IPOL */
+ /*
+ * IRPOST with literal data
+ * ...stack 0 is count
+ * ...stack 1 is literal data
+ */
+ IF_CHECK_STACK(2)
+ {
+ count = (unsigned int) stack[--stack_ptr];
+ long_temp = stack[--stack_ptr];
+ jbi_make_dword(charbuf, long_temp);
+ status = jbi_set_ir_postamble(count, 0, charbuf);
+ }
+ break;
+
+ case 0x24: /* PCHR */
+ IF_CHECK_STACK(1)
+ {
+ unsigned char ch;
+ count = jbi_strlen(message_buffer);
+ ch = (char) stack[--stack_ptr];
+ if ((ch < 1) || (ch > 127))
+ {
+ /* character code out of range */
+ /* instead of flagging an error, force the value to 127 */
+ ch = 127;
+ }
+ message_buffer[count] = ch;
+ message_buffer[count + 1] = '\0';
+ }
+ break;
+
+ case 0x25: /* EXIT */
+ IF_CHECK_STACK(1)
+ {
+ *exit_code = (int) stack[--stack_ptr];
+ }
+ done = 1;
+ break;
+
+ case 0x26: /* EQU */
+ IF_CHECK_STACK(2)
+ {
+ --stack_ptr;
+ stack[stack_ptr - 1] =
+ (stack[stack_ptr - 1] == stack[stack_ptr]) ? 1L : 0L;
+ }
+ break;
+
+ case 0x27: /* POPT */
+ IF_CHECK_STACK(1)
+ {
+ --stack_ptr;
+ }
+ break;
+
+ case 0x28: /* TRST */
+ bad_opcode = 1;
+ break;
+
+ case 0x29: /* FRQ */
+ bad_opcode = 1;
+ break;
+
+ case 0x2A: /* FRQU */
+ bad_opcode = 1;
+ break;
+
+ case 0x2B: /* PD32 */
+ bad_opcode = 1;
+ break;
+
+ case 0x2C: /* ABS */
+ IF_CHECK_STACK(1)
+ {
+ if (stack[stack_ptr - 1] < 0)
+ {
+ stack[stack_ptr - 1] = 0 - stack[stack_ptr - 1];
+ }
+ }
+ break;
+
+ case 0x2D: /* BCH0 */
+ /*
+ * Batch operation 0
+ * SWP
+ * SWPN 7
+ * SWP
+ * SWPN 6
+ * DUPN 8
+ * SWPN 2
+ * SWP
+ * DUPN 6
+ * DUPN 6
+ */
+
+ /* SWP */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[stack_ptr - 2];
+ stack[stack_ptr - 2] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* SWPN 7 */
+ index = 7 + 1;
+ IF_CHECK_STACK(index)
+ {
+ long_temp = stack[stack_ptr - index];
+ stack[stack_ptr - index] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* SWP */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[stack_ptr - 2];
+ stack[stack_ptr - 2] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* SWPN 6 */
+ index = 6 + 1;
+ IF_CHECK_STACK(index)
+ {
+ long_temp = stack[stack_ptr - index];
+ stack[stack_ptr - index] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* DUPN 8 */
+ index = 8 + 1;
+ IF_CHECK_STACK(index)
+ {
+ stack[stack_ptr] = stack[stack_ptr - index];
+ ++stack_ptr;
+ }
+
+ /* SWPN 2 */
+ index = 2 + 1;
+ IF_CHECK_STACK(index)
+ {
+ long_temp = stack[stack_ptr - index];
+ stack[stack_ptr - index] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* SWP */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[stack_ptr - 2];
+ stack[stack_ptr - 2] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+
+ /* DUPN 6 */
+ index = 6 + 1;
+ IF_CHECK_STACK(index)
+ {
+ stack[stack_ptr] = stack[stack_ptr - index];
+ ++stack_ptr;
+ }
+
+ /* DUPN 6 */
+ index = 6 + 1;
+ IF_CHECK_STACK(index)
+ {
+ stack[stack_ptr] = stack[stack_ptr - index];
+ ++stack_ptr;
+ }
+ break;
+
+ case 0x2E: /* BCH1 */
+ /*
+ * Batch operation 1
+ * SWPN 8
+ * SWP
+ * SWPN 9
+ * SWPN 3
+ * SWP
+ * SWPN 2
+ * SWP
+ * SWPN 7
+ * SWP
+ * SWPN 6
+ * DUPN 5
+ * DUPN 5
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x2F: /* PSH0 */
+ stack[stack_ptr++] = 0;
+ break;
+
+ case 0x40: /* PSHL */
+ stack[stack_ptr++] = (long) args[0];
+ break;
+
+ case 0x41: /* PSHV */
+ stack[stack_ptr++] = variables[args[0]];
+ break;
+
+ case 0x42: /* JMP */
+ pc = args[0] + code_section;
+ CHECK_PC;
+ break;
+
+ case 0x43: /* CALL */
+ stack[stack_ptr++] = pc;
+ pc = args[0] + code_section;
+ CHECK_PC;
+ break;
+
+ case 0x44: /* NEXT */
+ /*
+ * Process FOR / NEXT loop
+ * ...argument 0 is variable ID
+ * ...stack 0 is step value
+ * ...stack 1 is end value
+ * ...stack 2 is top address
+ */
+ IF_CHECK_STACK(3)
+ {
+ long step = stack[stack_ptr - 1];
+ long end = stack[stack_ptr - 2];
+ long top = stack[stack_ptr - 3];
+ long iterator = variables[args[0]];
+ int break_out = 0;
+
+ if (step < 0)
+ {
+ if (iterator <= end) break_out = 1;
+ }
+ else
+ {
+ if (iterator >= end) break_out = 1;
+ }
+
+ if (break_out)
+ {
+ stack_ptr -= 3;
+ }
+ else
+ {
+ variables[args[0]] = iterator + step;
+ pc = top + code_section;
+ CHECK_PC;
+ }
+ }
+ break;
+
+ case 0x45: /* PSTR */
+ /*
+ * PRINT add string
+ * ...argument 0 is string ID
+ */
+#if PORT==DOS
+ long_index = string_table + args[0];
+ index2 = jbi_strlen(message_buffer);
+
+ do
+ {
+ i = GET_BYTE(long_index);
+ message_buffer[index2] = (char) i;
+ ++long_index;
+ ++index2;
+ }
+ while ((i != '\0') && (index2 < JBIC_MESSAGE_LENGTH));
+#else
+ count = jbi_strlen(message_buffer);
+ jbi_strncpy(&message_buffer[count],
+ (char *) &program[string_table + args[0]],
+ JBIC_MESSAGE_LENGTH - count);
+#endif
+ message_buffer[JBIC_MESSAGE_LENGTH] = '\0';
+ break;
+
+ case 0x46: /* VMAP */
+ /*
+ * VMAP add signal name
+ * ...argument 0 is string ID
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x47: /* SINT */
+ /*
+ * STATE intermediate state
+ * ...argument 0 is state code
+ */
+ status = jbi_goto_jtag_state((int) args[0]);
+ break;
+
+ case 0x48: /* ST */
+ /*
+ * STATE final state
+ * ...argument 0 is state code
+ */
+ status = jbi_goto_jtag_state((int) args[0]);
+ break;
+
+ case 0x49: /* ISTP */
+ /*
+ * IRSTOP state
+ * ...argument 0 is state code
+ */
+ status = jbi_set_irstop_state((int) args[0]);
+ break;
+
+ case 0x4A: /* DSTP */
+ /*
+ * DRSTOP state
+ * ...argument 0 is state code
+ */
+ status = jbi_set_drstop_state((int) args[0]);
+ break;
+
+ case 0x4B: /* SWPN */
+ /*
+ * Exchange top with Nth stack value
+ * ...argument 0 is 0-based stack entry to swap with top element
+ */
+ index = ((int) args[0]) + 1;
+ IF_CHECK_STACK(index)
+ {
+ long_temp = stack[stack_ptr - index];
+ stack[stack_ptr - index] = stack[stack_ptr - 1];
+ stack[stack_ptr - 1] = long_temp;
+ }
+ break;
+
+ case 0x4C: /* DUPN */
+ /*
+ * Duplicate Nth stack value
+ * ...argument 0 is 0-based stack entry to duplicate
+ */
+ index = ((int) args[0]) + 1;
+ IF_CHECK_STACK(index)
+ {
+ stack[stack_ptr] = stack[stack_ptr - index];
+ ++stack_ptr;
+ }
+ break;
+
+ case 0x4D: /* POPV */
+ /*
+ * Pop stack into scalar variable
+ * ...argument 0 is variable ID
+ * ...stack 0 is value
+ */
+ IF_CHECK_STACK(1)
+ {
+ variables[args[0]] = stack[--stack_ptr];
+ }
+ break;
+
+ case 0x4E: /* POPE */
+ /*
+ * Pop stack into integer array element
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is value
+ */
+ IF_CHECK_STACK(2)
+ {
+ variable_id = (unsigned int) args[0];
+
+ /*
+ * If variable is read-only, convert to writable array
+ */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x1c))
+ {
+ /*
+ * Allocate a writable buffer for this array
+ */
+ count = (unsigned int) variable_size[variable_id];
+ long_temp = variables[variable_id];
+ longptr_temp = (long *) jbi_malloc(count * sizeof(long));
+ variables[variable_id] = (addr_t) longptr_temp;
+
+ if (variables[variable_id] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ /* copy previous contents into buffer */
+ for (i = 0; i < count; ++i)
+ {
+ longptr_temp[i] = GET_DWORD(long_temp);
+ long_temp += 4L;
+ }
+
+ /* set bit 7 - buffer was dynamically allocated */
+ attributes[variable_id] |= 0x80;
+
+ /* clear bit 2 - variable is writable */
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+ }
+
+#if PORT==DOS
+ /* for 16-bit version, allow writing in allocated buffers */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x9c))
+ {
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+#endif
+
+ /* check that variable is a writable integer array */
+ if ((attributes[variable_id] & 0x1c) != 0x18)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ longptr_temp = (long *) variables[variable_id];
+
+ /* pop the array index */
+ index = (unsigned int) stack[--stack_ptr];
+
+ /* pop the value and store it into the array */
+ longptr_temp[index] = stack[--stack_ptr];
+ }
+ }
+ break;
+
+ case 0x4F: /* POPA */
+ /*
+ * Pop stack into Boolean array
+ * ...argument 0 is variable ID
+ * ...stack 0 is count
+ * ...stack 1 is array index
+ * ...stack 2 is value
+ */
+ IF_CHECK_STACK(3)
+ {
+ variable_id = (unsigned int) args[0];
+
+ /*
+ * If variable is read-only, convert to writable array
+ */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x0c))
+ {
+ /*
+ * Allocate a writable buffer for this array
+ */
+ long_temp = (variable_size[variable_id] + 7L) >> 3L;
+ charptr_temp2 = (unsigned char *) variables[variable_id];
+ charptr_temp = jbi_malloc((unsigned int) long_temp);
+ variables[variable_id] = (addr_t) charptr_temp;
+
+ if (variables[variable_id] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ /* zero the buffer */
+ for (long_index = 0L;
+ long_index < long_temp;
+ ++long_index)
+ {
+ charptr_temp[long_index] = 0;
+ }
+
+ /* copy previous contents into buffer */
+ for (long_index = 0L;
+ long_index < variable_size[variable_id];
+ ++long_index)
+ {
+#if PORT==DOS
+ if ((attributes[variable_id] & 0x02) &&
+ ((long_index & 0x0000FFFF) == 0L))
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (long_index >> 16), version);
+ charptr_temp = jbi_aca_out_buffer;
+ long_index2 = long_index & 0xFFFF;
+ }
+#else
+ long_index2 = long_index;
+#endif
+
+ if (charptr_temp2[long_index2 >> 3] &
+ (1 << (long_index2 & 7)))
+ {
+ charptr_temp[long_index >> 3] |=
+ (1 << (long_index & 7));
+ }
+ }
+
+ /* set bit 7 - buffer was dynamically allocated */
+ attributes[variable_id] |= 0x80;
+
+ /* clear bit 2 - variable is writable */
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+ }
+
+#if PORT==DOS
+ /* for 16-bit version, allow writing in allocated buffers */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x8c))
+ {
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+#endif
+
+ /* check that variable is a writable Boolean array */
+ if ((attributes[variable_id] & 0x1c) != 0x08)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ charptr_temp = (unsigned char *) variables[variable_id];
+
+ /* pop the count (number of bits to copy) */
+ long_count = stack[--stack_ptr];
+
+ /* pop the array index */
+ long_index = stack[--stack_ptr];
+
+ reverse = 0;
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+
+ if (long_index > long_count)
+ {
+ reverse = 1;
+ long_temp = long_count;
+ long_count = 1 + long_index - long_count;
+ long_index = long_temp;
+
+ /* reverse POPA is not supported */
+ status = JBIC_BOUNDS_ERROR;
+ break;
+ }
+ else
+ {
+ long_count = 1 + long_count - long_index;
+ }
+ }
+
+ /* pop the data */
+ long_temp = stack[--stack_ptr];
+
+ if (long_count < 1)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ for (i = 0; i < (unsigned int) long_count; ++i)
+ {
+ if (long_temp & (1L << (long) i))
+ {
+ charptr_temp[long_index >> 3L] |=
+ (1L << (long_index & 7L));
+ }
+ else
+ {
+ charptr_temp[long_index >> 3L] &=
+ ~ (unsigned int) (1L << (long_index & 7L));
+ }
+ ++long_index;
+ }
+ }
+ }
+ }
+ break;
+
+ case 0x50: /* JMPZ */
+ /*
+ * Pop stack and branch if zero
+ * ...argument 0 is address
+ * ...stack 0 is condition value
+ */
+ IF_CHECK_STACK(1)
+ {
+ if (stack[--stack_ptr] == 0)
+ {
+ pc = args[0] + code_section;
+ CHECK_PC;
+ }
+ }
+ break;
+
+ case 0x51: /* DS */
+ case 0x52: /* IS */
+ /*
+ * DRSCAN
+ * IRSCAN
+ * ...argument 0 is scan data variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_index = stack[--stack_ptr];
+ long_count = stack[--stack_ptr];
+
+ reverse = 0;
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ /* stack 2 = count */
+ long_temp = long_count;
+ long_count = stack[--stack_ptr];
+
+ if (long_index > long_temp)
+ {
+ reverse = 1;
+ long_index = long_temp;
+ }
+ }
+
+#if PORT==DOS
+ if (((long_index & 0xFFFF0000) == 0) &&
+ ((long_count & 0xFFFF0000) == 0))
+ {
+ variable_id = (unsigned int) args[0];
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (long_index >> 16), version);
+ long_index &= 0x0000ffff;
+ charptr_temp = jbi_aca_out_buffer;
+ }
+ else
+ {
+ charptr_temp = (unsigned char *) variables[variable_id];
+ }
+
+ if (reverse)
+ {
+ /* allocate a buffer and reverse the data order */
+ charptr_temp2 = charptr_temp;
+ charptr_temp = jbi_malloc((unsigned int)
+ ((long_count >> 3L) + 1L));
+
+ if (charptr_temp == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ long_temp = long_index + long_count - 1;
+ long_index2 = 0;
+ while (long_index2 < long_count)
+ {
+ if (charptr_temp2[long_temp >> 3] &
+ (1 << (long_temp & 7)))
+ {
+ charptr_temp[long_index2 >> 3] |=
+ (1 << (long_index2 & 7));
+ }
+ else
+ {
+ charptr_temp[long_index2 >> 3] &=
+ ~(1 << (long_index2 & 7));
+ }
+
+ --long_temp;
+ ++long_index2;
+ }
+ }
+ }
+
+ if (opcode == 0x51) /* DS */
+ {
+ status = jbi_do_drscan((unsigned int) long_count,
+ charptr_temp, (unsigned long) long_index);
+ }
+ else /* IS */
+ {
+ status = jbi_do_irscan((unsigned int) long_count,
+ charptr_temp, (unsigned int) long_index);
+ }
+
+ if (reverse) jbi_free(charptr_temp);
+ }
+ else if ((opcode == 0x51) && !reverse)
+ {
+ status = jbi_do_drscan_multi_page(
+ (unsigned int) args[0],
+ (unsigned long) long_count,
+ (unsigned long) long_index, version);
+ }
+ else
+ {
+ /* reverse multi-page scans are not supported */
+ /* multi-page IR scans are not supported */
+ status = JBIC_BOUNDS_ERROR;
+ }
+#else
+ charptr_temp = (unsigned char *) variables[args[0]];
+
+ if (reverse)
+ {
+ /* allocate a buffer and reverse the data order */
+ charptr_temp2 = charptr_temp;
+ charptr_temp = jbi_malloc((long_count >> 3) + 1);
+ if (charptr_temp == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ long_temp = long_index + long_count - 1;
+ long_index2 = 0;
+ while (long_index2 < long_count)
+ {
+ if (charptr_temp2[long_temp >> 3] &
+ (1 << (long_temp & 7)))
+ {
+ charptr_temp[long_index2 >> 3] |=
+ (1 << (long_index2 & 7));
+ }
+ else
+ {
+ charptr_temp[long_index2 >> 3] &=
+ ~(1 << (long_index2 & 7));
+ }
+
+ --long_temp;
+ ++long_index2;
+ }
+ }
+ }
+
+ if (opcode == 0x51) /* DS */
+ {
+ status = jbi_do_drscan((unsigned int) long_count,
+ charptr_temp, (unsigned long) long_index);
+ }
+ else /* IS */
+ {
+ status = jbi_do_irscan((unsigned int) long_count,
+ charptr_temp, (unsigned int) long_index);
+ }
+#endif
+
+ if (reverse && (charptr_temp != NULL))
+ {
+ jbi_free(charptr_temp);
+ }
+ }
+ break;
+
+ case 0x53: /* DPRA */
+ /*
+ * DRPRE with array data
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ index = (unsigned int) stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ count = 1 + count - index;
+ }
+
+ charptr_temp = (unsigned char *) variables[args[0]];
+ status = jbi_set_dr_preamble(count, index, charptr_temp);
+ }
+ break;
+
+ case 0x54: /* DPOA */
+ /*
+ * DRPOST with array data
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ index = (unsigned int) stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ count = 1 + count - index;
+ }
+
+ charptr_temp = (unsigned char *) variables[args[0]];
+ status = jbi_set_dr_postamble(count, index, charptr_temp);
+ }
+ break;
+
+ case 0x55: /* IPRA */
+ /*
+ * IRPRE with array data
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ index = (unsigned int) stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ count = 1 + count - index;
+ }
+
+ charptr_temp = (unsigned char *) variables[args[0]];
+ status = jbi_set_ir_preamble(count, index, charptr_temp);
+ }
+ break;
+
+ case 0x56: /* IPOA */
+ /*
+ * IRPOST with array data
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ * ...stack 1 is count
+ */
+ IF_CHECK_STACK(2)
+ {
+ index = (unsigned int) stack[--stack_ptr];
+ count = (unsigned int) stack[--stack_ptr];
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ count = 1 + count - index;
+ }
+
+ charptr_temp = (unsigned char *) variables[args[0]];
+ status = jbi_set_ir_postamble(count, index, charptr_temp);
+ }
+ break;
+
+ case 0x57: /* EXPT */
+ /*
+ * EXPORT
+ * ...argument 0 is string ID
+ * ...stack 0 is integer expression
+ */
+ IF_CHECK_STACK(1)
+ {
+#if PORT==DOS
+ name_id = args[0];
+ for (j = 0; j < 32; ++j)
+ {
+ name[j] = GET_BYTE(string_table + name_id + j);
+ }
+ name[32] = '\0';
+#else
+ name = (char *) &program[string_table + args[0]];
+#endif
+ long_temp = stack[--stack_ptr];
+ jbi_export_integer(name, long_temp);
+ }
+ break;
+
+ case 0x58: /* PSHE */
+ /*
+ * Push integer array element
+ * ...argument 0 is variable ID
+ * ...stack 0 is array index
+ */
+ IF_CHECK_STACK(1)
+ {
+ variable_id = (unsigned int) args[0];
+ index = (unsigned int) stack[stack_ptr - 1];
+
+ /* check variable type */
+ if ((attributes[variable_id] & 0x1f) == 0x19)
+ {
+ /* writable integer array */
+ longptr_temp = (long *) variables[variable_id];
+ stack[stack_ptr - 1] = longptr_temp[index];
+ }
+ else if ((attributes[variable_id] & 0x1f) == 0x1c)
+ {
+ /* read-only integer array */
+ long_temp = variables[variable_id] + (4L * index);
+ stack[stack_ptr - 1] = GET_DWORD(long_temp);
+ }
+ else
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ }
+ break;
+
+ case 0x59: /* PSHA */
+ /*
+ * Push Boolean array
+ * ...argument 0 is variable ID
+ * ...stack 0 is count
+ * ...stack 1 is array index
+ */
+ IF_CHECK_STACK(2)
+ {
+ variable_id = (unsigned int) args[0];
+
+ /* check that variable is a Boolean array */
+ if ((attributes[variable_id] & 0x18) != 0x08)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ charptr_temp = (unsigned char *) variables[variable_id];
+
+ /* pop the count (number of bits to copy) */
+ count = (unsigned int) stack[--stack_ptr];
+
+ /* pop the array index */
+ index = (unsigned int) stack[stack_ptr - 1];
+
+ if (version > 0)
+ {
+ /* stack 0 = array right index */
+ /* stack 1 = array left index */
+ count = 1 + count - index;
+ }
+
+ if ((count < 1) || (count > 32))
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+#if PORT==DOS
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (stack[stack_ptr - 1] >> 16), version);
+ charptr_temp = jbi_aca_out_buffer;
+ }
+#endif
+ long_temp = 0L;
+
+ for (i = 0; i < count; ++i)
+ {
+ if (charptr_temp[(i + index) >> 3] &
+ (1 << ((i + index) & 7)))
+ {
+ long_temp |= (1L << i);
+ }
+ }
+
+ stack[stack_ptr - 1] = long_temp;
+ }
+ }
+ }
+ break;
+
+ case 0x5A: /* DYNA */
+ /*
+ * Dynamically change size of array
+ * ...argument 0 is variable ID
+ * ...stack 0 is new size
+ */
+ IF_CHECK_STACK(1)
+ {
+ variable_id = (unsigned int) args[0];
+ long_temp = stack[--stack_ptr];
+
+ if (long_temp > variable_size[variable_id])
+ {
+ variable_size[variable_id] = long_temp;
+
+ if (attributes[variable_id] & 0x10)
+ {
+ /* allocate integer array */
+ long_temp *= 4;
+ }
+ else
+ {
+ /* allocate Boolean array */
+ long_temp = (long_temp + 7) >> 3;
+ }
+
+ /*
+ * If the buffer was previously allocated, free it
+ */
+ if ((attributes[variable_id] & 0x80) &&
+ (variables[variable_id] != (addr_t) NULL))
+ {
+ jbi_free((void *) variables[variable_id]);
+ variables[variable_id] = (addr_t) NULL;
+ }
+
+ /*
+ * Allocate a new buffer of the requested size
+ */
+ variables[variable_id] = (addr_t)
+ jbi_malloc((unsigned int) long_temp);
+
+ if (variables[variable_id] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ /*
+ * Set the attribute bit to indicate that this buffer
+ * was dynamically allocated and should be freed later
+ */
+ attributes[variable_id] |= 0x80;
+
+ /* zero out memory */
+ count = (unsigned int)
+ ((variable_size[variable_id] + 7L) / 8L);
+ charptr_temp = (unsigned char *)
+ (variables[variable_id]);
+ for (index = 0; index < count; ++index)
+ {
+ charptr_temp[index] = 0;
+ }
+ }
+ }
+ }
+ break;
+
+ case 0x5B: /* EXPR */
+ bad_opcode = 1;
+ break;
+
+ case 0x5C: /* EXPV */
+ /*
+ * Export Boolean array
+ * ...argument 0 is string ID
+ * ...stack 0 is variable ID
+ * ...stack 1 is array right index
+ * ...stack 2 is array left index
+ */
+ IF_CHECK_STACK(3)
+ {
+ if (version == 0)
+ {
+ /* EXPV is not supported in JBC 1.0 */
+ bad_opcode = 1;
+ break;
+ }
+#if PORT==DOS
+ name_id = args[0];
+ for (j = 0; j < 32; ++j)
+ {
+ name[j] = GET_BYTE(string_table + name_id + j);
+ }
+ name[32] = '\0';
+#else
+ name = (char *) &program[string_table + args[0]];
+#endif
+ variable_id = (unsigned int) stack[--stack_ptr];
+ long_index = stack[--stack_ptr]; /* right index */
+ long_index2 = stack[--stack_ptr]; /* left index */
+
+ if (long_index > long_index2)
+ {
+ /* reverse indices not supported */
+ status = JBIC_BOUNDS_ERROR;
+ break;
+ }
+
+ long_count = 1 + long_index2 - long_index;
+
+ charptr_temp = (unsigned char *) variables[variable_id];
+ charptr_temp2 = NULL;
+
+#if PORT==DOS
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (long_index >> 16), version);
+ charptr_temp = jbi_aca_out_buffer;
+ long_index &= 0x0000FFFF;
+ }
+#endif
+
+ if ((long_index & 7L) != 0)
+ {
+ charptr_temp2 = jbi_malloc((unsigned int)
+ ((long_count + 7L) / 8L));
+ if (charptr_temp2 == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ long k = long_index;
+ for (i = 0; i < (unsigned int) long_count; ++i)
+ {
+ if (charptr_temp[k >> 3] & (1 << (k & 7)))
+ {
+ charptr_temp2[i >> 3] |= (1 << (i & 7));
+ }
+ else
+ {
+ charptr_temp2[i >> 3] &= ~(1 << (i & 7));
+ }
+
+ ++k;
+ }
+ charptr_temp = charptr_temp2;
+ }
+ }
+ else if (long_index != 0)
+ {
+ charptr_temp = &charptr_temp[long_index >> 3];
+ }
+
+ jbi_export_boolean_array(name, charptr_temp, long_count);
+
+ /* free allocated buffer */
+ if (((long_index & 7L) != 0) && (charptr_temp2 != NULL))
+ {
+ jbi_free(charptr_temp2);
+ }
+ }
+ break;
+
+ case 0x80: /* COPY */
+ /*
+ * Array copy
+ * ...argument 0 is dest ID
+ * ...argument 1 is source ID
+ * ...stack 0 is count
+ * ...stack 1 is dest index
+ * ...stack 2 is source index
+ */
+ IF_CHECK_STACK(3)
+ {
+ long copy_count = stack[--stack_ptr];
+ long copy_index = stack[--stack_ptr];
+ long copy_index2 = stack[--stack_ptr];
+ long destleft;
+ long src_count;
+ long dest_count;
+ int src_reverse = 0;
+ int dest_reverse = 0;
+
+ reverse = 0;
+
+ if (version > 0)
+ {
+ /* stack 0 = source right index */
+ /* stack 1 = source left index */
+ /* stack 2 = destination right index */
+ /* stack 3 = destination left index */
+ destleft = stack[--stack_ptr];
+
+ if (copy_count > copy_index)
+ {
+ src_reverse = 1;
+ reverse = 1;
+ src_count = 1 + copy_count - copy_index;
+ /* copy_index = source start index */
+ }
+ else
+ {
+ src_count = 1 + copy_index - copy_count;
+ copy_index = copy_count; /* source start index */
+ }
+
+ if (copy_index2 > destleft)
+ {
+ dest_reverse = 1;
+ reverse = !reverse;
+ dest_count = 1 + copy_index2 - destleft;
+ copy_index2 = destleft; /* destination start index */
+ }
+ else
+ {
+ dest_count = 1 + destleft - copy_index2;
+ /* copy_index2 = destination start index */
+ }
+
+ copy_count = (src_count < dest_count) ? src_count : dest_count;
+
+ if ((src_reverse || dest_reverse) &&
+ (src_count != dest_count))
+ {
+ /* If either the source or destination is reversed, */
+ /* we can't tolerate a length mismatch, because we */
+ /* "left justify" the arrays when copying. This */
+ /* won't work correctly with reversed arrays. */
+ status = JBIC_BOUNDS_ERROR;
+ }
+ }
+
+ count = (unsigned int) copy_count;
+ index = (unsigned int) copy_index;
+ index2 = (unsigned int) copy_index2;
+
+ /*
+ * If destination is a read-only array, allocate a buffer
+ * and convert it to a writable array
+ */
+ variable_id = (unsigned int) args[1];
+ if ((version > 0) && ((attributes[variable_id] & 0x9c) == 0x0c))
+ {
+ /*
+ * Allocate a writable buffer for this array
+ */
+ long_temp = (variable_size[variable_id] + 7L) >> 3L;
+ charptr_temp2 = (unsigned char *) variables[variable_id];
+ charptr_temp = jbi_malloc((unsigned int) long_temp);
+ variables[variable_id] = (addr_t) charptr_temp;
+
+ if (variables[variable_id] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ /* zero the buffer */
+ for (long_index = 0L;
+ long_index < long_temp;
+ ++long_index)
+ {
+ charptr_temp[long_index] = 0;
+ }
+
+ /* copy previous contents into buffer */
+ for (long_index = 0L;
+ long_index < variable_size[variable_id];
+ ++long_index)
+ {
+#if PORT==DOS
+ if ((attributes[variable_id] & 0x02) &&
+ ((long_index & 0x0000FFFF) == 0L))
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (long_index >> 16), version);
+ charptr_temp = jbi_aca_out_buffer;
+ long_index2 = long_index & 0xFFFF;
+ }
+#else
+ long_index2 = long_index;
+#endif
+
+ if (charptr_temp2[long_index2 >> 3] &
+ (1 << (long_index2 & 7)))
+ {
+ charptr_temp[long_index >> 3] |=
+ (1 << (long_index & 7));
+ }
+ }
+
+ /* set bit 7 - buffer was dynamically allocated */
+ attributes[variable_id] |= 0x80;
+
+ /* clear bit 2 - variable is writable */
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+ }
+
+#if PORT==DOS
+ /* for 16-bit version, allow writing in allocated buffers */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x8c))
+ {
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+#endif
+
+ charptr_temp = (unsigned char *) variables[args[1]];
+ charptr_temp2 = (unsigned char *) variables[args[0]];
+
+#if PORT==DOS
+ variable_id = (unsigned int) args[0];
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (copy_index >> 16), version);
+ charptr_temp2 = jbi_aca_out_buffer;
+ }
+#endif
+
+ /* check that destination is a writable Boolean array */
+ if ((attributes[args[1]] & 0x1c) != 0x08)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ break;
+ }
+
+ if (count < 1)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+ if (reverse)
+ {
+ index2 += (count - 1);
+ }
+
+ for (i = 0; i < count; ++i)
+ {
+ if (charptr_temp2[index >> 3] & (1 << (index & 7)))
+ {
+ charptr_temp[index2 >> 3] |= (1 << (index2 & 7));
+ }
+ else
+ {
+ charptr_temp[index2 >> 3] &=
+ ~(unsigned int) (1 << (index2 & 7));
+ }
+ ++index;
+ if (reverse) --index2; else ++index2;
+ }
+ }
+ }
+ break;
+
+ case 0x81: /* REVA */
+ /*
+ * ARRAY COPY reversing bit order
+ * ...argument 0 is dest ID
+ * ...argument 1 is source ID
+ * ...stack 0 is dest index
+ * ...stack 1 is source index
+ * ...stack 2 is count
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0x82: /* DSC */
+ case 0x83: /* ISC */
+ /*
+ * DRSCAN with capture
+ * IRSCAN with capture
+ * ...argument 0 is scan data variable ID
+ * ...argument 1 is capture variable ID
+ * ...stack 0 is capture index
+ * ...stack 1 is scan data index
+ * ...stack 2 is count
+ */
+ IF_CHECK_STACK(3)
+ {
+ long scan_right, scan_left;
+ long capture_count = 0;
+ long scan_count = 0;
+ long capture_index = stack[--stack_ptr];
+ long scan_index = stack[--stack_ptr];
+ if (version > 0)
+ {
+ /* stack 0 = capture right index */
+ /* stack 1 = capture left index */
+ /* stack 2 = scan right index */
+ /* stack 3 = scan left index */
+ /* stack 4 = count */
+ scan_right = stack[--stack_ptr];
+ scan_left = stack[--stack_ptr];
+ capture_count = 1 + scan_index - capture_index;
+ scan_count = 1 + scan_left - scan_right;
+ scan_index = scan_right;
+ }
+ long_count = stack[--stack_ptr];
+
+ /*
+ * If capture array is read-only, allocate a buffer
+ * and convert it to a writable array
+ */
+ variable_id = (unsigned int) args[1];
+ if ((version > 0) && ((attributes[variable_id] & 0x9c) == 0x0c))
+ {
+ /*
+ * Allocate a writable buffer for this array
+ */
+ long_temp = (variable_size[variable_id] + 7L) >> 3L;
+ charptr_temp2 = (unsigned char *) variables[variable_id];
+ charptr_temp = jbi_malloc((unsigned int) long_temp);
+ variables[variable_id] = (addr_t) charptr_temp;
+
+ if (variables[variable_id] == (addr_t) NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ break;
+ }
+ else
+ {
+ /* zero the buffer */
+ for (long_index = 0L;
+ long_index < long_temp;
+ ++long_index)
+ {
+ charptr_temp[long_index] = 0;
+ }
+
+ /* copy previous contents into buffer */
+ for (long_index = 0L;
+ long_index < variable_size[variable_id];
+ ++long_index)
+ {
+#if PORT==DOS
+ if ((attributes[variable_id] & 0x02) &&
+ ((long_index & 0x0000FFFF) == 0L))
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (long_index >> 16), version);
+ charptr_temp = jbi_aca_out_buffer;
+ long_index2 = long_index & 0xFFFF;
+ }
+#else
+ long_index2 = long_index;
+#endif
+
+ if (charptr_temp2[long_index2 >> 3] &
+ (1 << (long_index2 & 7)))
+ {
+ charptr_temp[long_index >> 3] |=
+ (1 << (long_index & 7));
+ }
+ }
+
+ /* set bit 7 - buffer was dynamically allocated */
+ attributes[variable_id] |= 0x80;
+
+ /* clear bit 2 - variable is writable */
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+ }
+
+#if PORT==DOS
+ /* for 16-bit version, allow writing in allocated buffers */
+ if ((version > 0) &&
+ ((attributes[variable_id] & 0x9c) == 0x8c))
+ {
+ attributes[variable_id] &= ~0x04;
+ attributes[variable_id] |= 0x01;
+ }
+#endif
+
+ charptr_temp = (unsigned char *) variables[args[0]];
+ charptr_temp2 = (unsigned char *) variables[args[1]];
+
+#if PORT==DOS
+ variable_id = (unsigned int) args[0];
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ /* initialized compressed Boolean array */
+ jbi_uncompress_page(variable_id,
+ (int) (scan_index >> 16), version);
+ scan_index &= 0x0000ffff;
+ charptr_temp = jbi_aca_out_buffer;
+ }
+#endif
+
+ if ((version > 0) &&
+ ((long_count > capture_count) || (long_count > scan_count)))
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+
+ /* check that capture array is a writable Boolean array */
+ if ((attributes[args[1]] & 0x1c) != 0x08)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ if (opcode == 0x82) /* DSC */
+ {
+ status = jbi_swap_dr((unsigned int) long_count,
+ charptr_temp, (unsigned long) scan_index,
+ charptr_temp2, (unsigned int) capture_index);
+ }
+ else /* ISC */
+ {
+ status = jbi_swap_ir((unsigned int) long_count,
+ charptr_temp, (unsigned int) scan_index,
+ charptr_temp2, (unsigned int) capture_index);
+ }
+ }
+ }
+ break;
+
+ case 0x84: /* WAIT */
+ /*
+ * WAIT
+ * ...argument 0 is wait state
+ * ...argument 1 is end state
+ * ...stack 0 is cycles
+ * ...stack 1 is microseconds
+ */
+ IF_CHECK_STACK(2)
+ {
+ long_temp = stack[--stack_ptr];
+
+ if (long_temp != 0L)
+ {
+ status = jbi_do_wait_cycles(long_temp, (unsigned int) args[0]);
+ }
+
+ long_temp = stack[--stack_ptr];
+
+ if ((status == JBIC_SUCCESS) && (long_temp != 0L))
+ {
+ status = jbi_do_wait_microseconds(long_temp, (unsigned int) args[0]);
+ }
+
+ if ((status == JBIC_SUCCESS) && (args[1] != args[0]))
+ {
+ status = jbi_goto_jtag_state((unsigned int) args[1]);
+ }
+
+ if (version > 0)
+ {
+ --stack_ptr; /* throw away MAX cycles */
+ --stack_ptr; /* throw away MAX microseconds */
+ }
+ }
+ break;
+
+ case 0x85: /* VS */
+ /*
+ * VECTOR
+ * ...argument 0 is dir data variable ID
+ * ...argument 1 is scan data variable ID
+ * ...stack 0 is dir array index
+ * ...stack 1 is scan array index
+ * ...stack 2 is count
+ */
+ bad_opcode = 1;
+ break;
+
+ case 0xC0: /* CMPA */
+ /*
+ * Array compare
+ * ...argument 0 is source 1 ID
+ * ...argument 1 is source 2 ID
+ * ...argument 2 is mask ID
+ * ...stack 0 is source 1 index
+ * ...stack 1 is source 2 index
+ * ...stack 2 is mask index
+ * ...stack 3 is count
+ */
+ IF_CHECK_STACK(4)
+ {
+ long a, b;
+ unsigned char *source1 = (unsigned char *) variables[args[0]];
+ unsigned char *source2 = (unsigned char *) variables[args[1]];
+ unsigned char *mask = (unsigned char *) variables[args[2]];
+ unsigned long index1 = stack[--stack_ptr];
+ unsigned long index2 = stack[--stack_ptr];
+ unsigned long mask_index = stack[--stack_ptr];
+ long_count = stack[--stack_ptr];
+
+ if (version > 0)
+ {
+ /* stack 0 = source 1 right index */
+ /* stack 1 = source 1 left index */
+ /* stack 2 = source 2 right index */
+ /* stack 3 = source 2 left index */
+ /* stack 4 = mask right index */
+ /* stack 5 = mask left index */
+ long mask_right = stack[--stack_ptr];
+ long mask_left = stack[--stack_ptr];
+ a = 1 + index2 - index1; /* source 1 count */
+ b = 1 + long_count - mask_index; /* source 2 count */
+ a = (a < b) ? a : b;
+ b = 1 + mask_left - mask_right; /* mask count */
+ a = (a < b) ? a : b;
+ index2 = mask_index; /* source 2 start index */
+ mask_index = mask_right; /* mask start index */
+ long_count = a;
+ }
+
+ long_temp = 1L;
+
+ if (long_count < 1)
+ {
+ status = JBIC_BOUNDS_ERROR;
+ }
+ else
+ {
+#if PORT==DOS
+ variable_id = (unsigned int) args[0];
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ jbi_uncompress_page(variable_id,
+ (int) (index1 >> 16), version);
+ index1 &= 0x0000ffff;
+ source1 = jbi_aca_out_buffer;
+ }
+
+ variable_id = (unsigned int) args[1];
+ if ((attributes[variable_id] & 0x1e) == 0x0e)
+ {
+ jbi_uncompress_page(variable_id,
+ (int) (index2 >> 16), version);
+ index2 &= 0x0000ffff;
+ source2 = jbi_aca_out_buffer;
+ }
+#endif
+ count = (unsigned int) long_count;
+
+ for (i = 0; i < count; ++i)
+ {
+ if (mask[mask_index >> 3] & (1 << (mask_index & 7)))
+ {
+ a = source1[index1 >> 3] & (1 << (index1 & 7))
+ ? 1 : 0;
+ b = source2[index2 >> 3] & (1 << (index2 & 7))
+ ? 1 : 0;
+
+ if (a != b) long_temp = 0L; /* failure */
+ }
+ ++index1;
+ ++index2;
+ ++mask_index;
+ }
+ }
+
+ stack[stack_ptr++] = long_temp;
+ }
+ break;
+
+ case 0xC1: /* VSC */
+ /*
+ * VECTOR with capture
+ * ...argument 0 is dir data variable ID
+ * ...argument 1 is scan data variable ID
+ * ...argument 2 is capture variable ID
+ * ...stack 0 is capture index
+ * ...stack 1 is scan data index
+ * ...stack 2 is dir data index
+ * ...stack 3 is count
+ */
+ bad_opcode = 1;
+ break;
+
+ default:
+ /*
+ * Unrecognized opcode -- ERROR!
+ */
+ bad_opcode = 1;
+ break;
+ }
+
+ if (bad_opcode)
+ {
+ status = JBIC_ILLEGAL_OPCODE;
+ }
+
+ if ((stack_ptr < 0) || (stack_ptr >= JBI_STACK_SIZE))
+ {
+ status = JBIC_STACK_OVERFLOW;
+ }
+
+ if (status != JBIC_SUCCESS)
+ {
+ done = 1;
+ *error_address = (long) (opcode_address - code_section);
+ }
+ }
+ jbi_dbg(DEBUG_DETAIL, "debug_cnt(total): 0x%lx\n", debug_cnt);
+
+ jbi_dbg(DEBUG_NOISY, "jbi_free_jtag_padding_buffers\n");
+ jbi_free_jtag_padding_buffers(reset_jtag);
+
+ /*
+ * Free all dynamically allocated arrays
+ */
+ jbi_dbg(DEBUG_NOISY, "jbi_free_attributes\n");
+ if ((attributes != NULL) && (variables != NULL))
+ {
+ for (i = 0; i < (unsigned int) symbol_count; ++i)
+ {
+ if ((attributes[i] & 0x80) && (variables[i] != (addr_t) NULL)
+ && (variables[i] != (addr_t) 1))
+ {
+ jbi_free((void *) variables[i]);
+ }
+ }
+ }
+
+ if (variables != NULL) jbi_free(variables);
+
+ if (variable_size != NULL) jbi_free(variable_size);
+
+ if (attributes != NULL) jbi_free(attributes);
+
+ if (proc_attributes != NULL) jbi_free(proc_attributes);
+
+ jbi_dbg(DEBUG_NOISY, "return status %d\n", status);
+ kfree(message_buffer);
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_get_note
+(
+ PROGRAM_PTR program,
+ long program_size,
+ long *offset,
+ char *key,
+ char *value,
+ int length
+)
+
+/* */
+/* Description: Gets key and value of NOTE fields in the JBC file. */
+/* Can be called in two modes: if offset pointer is NULL, */
+/* then the function searches for note fields which match */
+/* the key string provided. If offset is not NULL, then */
+/* the function finds the next note field of any key, */
+/* starting at the offset specified by the offset pointer. */
+/* */
+/* Returns: JBIC_SUCCESS for success, else appropriate error code */
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_UNEXPECTED_END;
+ unsigned long note_strings = 0L;
+ unsigned long note_table = 0L;
+ unsigned long note_count = 0L;
+ unsigned long first_word = 0L;
+ int version = 0;
+ int delta = 0;
+ char *key_ptr;
+ char *value_ptr;
+ int i;
+
+#if PORT==DOS
+ int count = 0;
+ int done = 0;
+ long long_index = 0;
+ char key_buffer[256];
+ char value_buffer[256];
+
+ jbi_program = program;
+#endif
+
+ /*
+ * Read header information
+ */
+ if (program_size > 52L)
+ {
+ first_word = GET_DWORD(0);
+ version = (int) (first_word & 1L);
+ delta = version * 8;
+
+ note_strings = GET_DWORD(8 + delta);
+ note_table = GET_DWORD(12 + delta);
+ note_count = GET_DWORD(44 + (2 * delta));
+ }
+
+ if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L))
+ {
+ status = JBIC_IO_ERROR;
+ }
+ else if (note_count > 0L)
+ {
+ if (offset == NULL)
+ {
+ /*
+ * We will search for the first note with a specific key, and
+ * return only the value
+ */
+ for (i = 0; (i < (int) note_count) && (status != JBIC_SUCCESS); ++i)
+ {
+#if PORT==DOS
+ done = 0;
+ count = 0;
+ long_index = note_strings + GET_DWORD(note_table + (8 * i));
+ while ((count < 255) && !done)
+ {
+ key_buffer[count] = GET_BYTE(long_index);
+ if (key_buffer[count] == '\0') done = 1;
+ ++long_index;
+ ++count;
+ }
+ key_buffer[255] = '\0';
+ key_ptr = key_buffer;
+#else
+ key_ptr = (char *) &program[note_strings +
+ GET_DWORD(note_table + (8 * i))];
+#endif
+ if ((key != NULL) && (jbi_stricmp(key, key_ptr) == 0))
+ {
+ status = JBIC_SUCCESS;
+
+#if PORT==DOS
+ done = 0;
+ count = 0;
+ long_index = note_strings + GET_DWORD(note_table + (8 * i) + 4);
+ while ((count < 255) && !done)
+ {
+ value_buffer[count] = GET_BYTE(long_index);
+ if (value_buffer[count] == '\0') done = 1;
+ ++long_index;
+ ++count;
+ }
+ value_buffer[255] = '\0';
+ value_ptr = value_buffer;
+#else
+ value_ptr = (char *) &program[note_strings +
+ GET_DWORD(note_table + (8 * i) + 4)];
+#endif
+
+ if (value != NULL)
+ {
+ jbi_strncpy(value, value_ptr, length);
+ }
+ }
+ }
+ }
+ else
+ {
+ /*
+ * We will search for the next note, regardless of the key, and
+ * return both the value and the key
+ */
+
+ i = (int) *offset;
+
+ if ((i >= 0) && (i < (int) note_count))
+ {
+ status = JBIC_SUCCESS;
+
+ if (key != NULL)
+ {
+#if PORT==DOS
+ done = 0;
+ count = 0;
+ long_index = note_strings +
+ GET_DWORD(note_table + (8 * i));
+
+ while ((count < length) && !done)
+ {
+ key[count] = GET_BYTE(long_index);
+ if (key[count] == '\0') done = 1;
+ ++long_index;
+ ++count;
+ }
+#else
+ jbi_strncpy(key, (char *) &program[note_strings +
+ GET_DWORD(note_table + (8 * i))], length);
+#endif
+ }
+
+ if (value != NULL)
+ {
+#if PORT==DOS
+ done = 0;
+ count = 0;
+ long_index = note_strings +
+ GET_DWORD(note_table + (8 * i) + 4);
+
+ while ((count < length) && !done)
+ {
+ value[count] = GET_BYTE(long_index);
+ if (value[count] == '\0') done = 1;
+ ++long_index;
+ ++count;
+ }
+#else
+ jbi_strncpy(value, (char *) &program[note_strings +
+ GET_DWORD(note_table + (8 * i) + 4)], length);
+#endif
+ }
+
+ *offset = i + 1;
+ }
+ }
+ }
+
+ return (status);
+}
+
+/****************************************************************************/
+/* */
+
+JBI_RETURN_TYPE jbi_check_crc
+(
+ PROGRAM_PTR program,
+ long program_size,
+ unsigned short *expected_crc,
+ unsigned short *actual_crc
+)
+
+/* */
+/* Description: This function reads the entire input file and computes */
+/* the CRC of everything up to the CRC field. */
+/* */
+/* Returns: JBIC_SUCCESS for success, JBIC_CRC_ERROR for failure */
+/* */
+/****************************************************************************/
+{
+ JBI_RETURN_TYPE status = JBIC_SUCCESS;
+ unsigned short local_expected, local_actual, shift_reg = 0xffff;
+ int bit, feedback;
+ unsigned char databyte;
+ unsigned long i;
+ unsigned long crc_section = 0L;
+ unsigned long first_word = 0L;
+ int version = 0;
+ int delta = 0;
+
+#if PORT==DOS
+ jbi_program = program;
+#endif
+
+ if (program_size > 52L)
+ {
+ first_word = GET_DWORD(0);
+ version = (int) (first_word & 1L);
+ delta = version * 8;
+
+ crc_section = GET_DWORD(32 + delta);
+ }
+
+ if ((first_word != 0x4A414D00L) && (first_word != 0x4A414D01L))
+ {
+ status = JBIC_IO_ERROR;
+ }
+
+ if (crc_section >= (unsigned long) program_size)
+ {
+ status = JBIC_IO_ERROR;
+ }
+
+ if (status == JBIC_SUCCESS)
+ {
+ local_expected = (unsigned short) GET_WORD(crc_section);
+ if (expected_crc != NULL) *expected_crc = local_expected;
+
+ for (i = 0; i < crc_section; ++i)
+ {
+ databyte = GET_BYTE(i);
+ for (bit = 0; bit < 8; bit++) /* compute for each bit */
+ {
+ feedback = (databyte ^ shift_reg) & 0x01;
+ shift_reg >>= 1; /* shift the shift register */
+ if (feedback) shift_reg ^= 0x8408; /* invert selected bits */
+ databyte >>= 1; /* get the next bit of input_byte */
+ }
+ }
+
+ local_actual = (unsigned short) ~shift_reg;
+ if (actual_crc != NULL) *actual_crc = local_actual;
+
+ if (local_expected != local_actual)
+ {
+ status = JBIC_CRC_ERROR;
+ }
+ }
+
+ return (status);
+}
+
+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 status = JBIC_IO_ERROR;
+ unsigned long first_word = 0;
+ int version = 0;
+
+#if PORT==DOS
+ jbi_program = program;
+#endif
+
+ /*
+ * Read header information
+ */
+ if (program_size > 52L)
+ {
+ first_word = GET_DWORD(0);
+
+ if ((first_word == 0x4A414D00L) || (first_word == 0x4A414D01L))
+ {
+ status = JBIC_SUCCESS;
+
+ version = (int) (first_word & 1L);
+ *format_version = version + 1;
+
+ if (version > 0)
+ {
+ *action_count = (int) GET_DWORD(48);
+ *procedure_count = (int) GET_DWORD(52);
+ }
+ }
+
+ }
+
+ return (status);
+}
+
+JBI_RETURN_TYPE jbi_get_action_info
+(
+ PROGRAM_PTR program,
+ long program_size,
+ int index,
+ char **name,
+ char **description,
+ JBI_PROCINFO **procedure_list
+)
+{
+ JBI_RETURN_TYPE status = JBIC_IO_ERROR;
+ JBI_PROCINFO *procptr = NULL;
+ JBI_PROCINFO *tmpptr = NULL;
+ unsigned long first_word = 0L;
+ unsigned long action_table = 0L;
+ unsigned long proc_table = 0L;
+ unsigned long string_table = 0L;
+ unsigned long note_strings = 0L;
+ unsigned long action_count = 0L;
+ unsigned long proc_count = 0L;
+ unsigned long act_name_id = 0L;
+ unsigned long act_desc_id = 0L;
+ unsigned long act_proc_id = 0L;
+ unsigned long act_proc_name = 0L;
+ unsigned char act_proc_attribute = 0;
+
+#if PORT==DOS
+ int i, length;
+ jbi_program = program;
+#endif
+
+ /*
+ * Read header information
+ */
+ if (program_size > 52L)
+ {
+ first_word = GET_DWORD(0);
+
+ if (first_word == 0x4A414D01L)
+ {
+ action_table = GET_DWORD(4);
+ proc_table = GET_DWORD(8);
+ string_table = GET_DWORD(12);
+ note_strings = GET_DWORD(16);
+ action_count = GET_DWORD(48);
+ proc_count = GET_DWORD(52);
+
+ if (index < (int) action_count)
+ {
+ act_name_id = GET_DWORD(action_table + (12 * index));
+ act_desc_id = GET_DWORD(action_table + (12 * index) + 4);
+ act_proc_id = GET_DWORD(action_table + (12 * index) + 8);
+
+#if PORT==DOS
+ length = 0;
+ while (GET_BYTE(string_table + act_name_id + length) != 0) ++length;
+ *name = jbi_malloc(length + 1);
+ if (*name == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ for (i = 0; i < length; ++i)
+ {
+ (*name)[i] = GET_BYTE(string_table + act_name_id + i);
+ }
+ (*name)[length] = '\0';
+ }
+#else
+ *name = (char *) &program[string_table + act_name_id];
+#endif
+
+ if (act_desc_id < (note_strings - string_table))
+ {
+#if PORT==DOS
+ length = 0;
+ while (GET_BYTE(string_table + act_desc_id + length) != 0) ++length;
+ *description = jbi_malloc(length + 1);
+ if (*description == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ for (i = 0; i < length; ++i)
+ {
+ (*description)[i] = GET_BYTE(string_table + act_desc_id + i);
+ }
+ (*description)[length] = '\0';
+ }
+#else
+ *description = (char *) &program[string_table + act_desc_id];
+#endif
+ }
+
+ do
+ {
+ act_proc_name = GET_DWORD(proc_table + (13 * act_proc_id));
+ act_proc_attribute = (unsigned char)
+ (GET_BYTE(proc_table + (13 * act_proc_id) + 8) & 0x03);
+
+ procptr = (JBI_PROCINFO *) jbi_malloc(sizeof(JBI_PROCINFO));
+
+ if (procptr == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+#if PORT==DOS
+ length = 0;
+ while (GET_BYTE(string_table + act_proc_name + length) != 0) ++length;
+ procptr->name = jbi_malloc(length + 1);
+ if (procptr->name == NULL)
+ {
+ status = JBIC_OUT_OF_MEMORY;
+ }
+ else
+ {
+ for (i = 0; i < length; ++i)
+ {
+ procptr->name[i] =
+ GET_BYTE(string_table + act_proc_name + i);
+ }
+ procptr->name[length] = '\0';
+ }
+#else
+ procptr->name = (char *)
+ &program[string_table + act_proc_name];
+#endif
+ procptr->attributes = act_proc_attribute;
+ procptr->next = NULL;
+
+ /* add record to end of linked list */
+ if (*procedure_list == NULL)
+ {
+ *procedure_list = procptr;
+ }
+ else
+ {
+ tmpptr = *procedure_list;
+ while (tmpptr->next != NULL) tmpptr = tmpptr->next;
+ tmpptr->next = procptr;
+ }
+ }
+
+ act_proc_id =
+ GET_DWORD(proc_table + (13 * act_proc_id) + 4);
+ }
+ while ((act_proc_id != 0) && (act_proc_id < proc_count));
+ }
+ }
+
+ }
+
+ return (status);
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiport.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiport.h
new file mode 100644
index 0000000000..28669dc81f
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbiport.h
@@ -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 */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.c
new file mode 100644
index 0000000000..396c92caca
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.c
@@ -0,0 +1,2518 @@
+/****************************************************************************/
+/* */
+/* Module: jbistub.c */
+/* */
+/* Copyright (C) Altera Corporation 1997-2001 */
+/* */
+/* Description: Jam STAPL ByteCode Player main source file */
+/* */
+/* Supports Altera ByteBlaster hardware download cable */
+/* on Windows 95 and Windows NT operating systems. */
+/* (A device driver is required for Windows NT.) */
+/* */
+/* Also supports BitBlaster hardware download cable on */
+/* Windows 95, Windows NT, and UNIX platforms. */
+/* */
+/* Revisions: 1.1 fixed control port initialization for ByteBlaster */
+/* 2.0 added support for STAPL bytecode format, added code */
+/* to get printer port address from Windows registry */
+/* 2.1 improved messages, fixed delay-calibration bug in */
+/* 16-bit DOS port, added support for "alternative */
+/* cable X", added option to control whether to reset */
+/* the TAP after execution, moved porting macros into */
+/* jbiport.h */
+/* 2.2 added support for static memory */
+/* fixed /W4 warnings */
+/* */
+/****************************************************************************/
+
+#ifndef NO_ALTERA_STDIO
+#define NO_ALTERA_STDIO
+#endif
+
+#if 0
+#if ( _MSC_VER >= 800 )
+#pragma warning(disable:4115)
+#pragma warning(disable:4201)
+#pragma warning(disable:4214)
+#pragma warning(disable:4514)
+#endif
+#endif
+
+#include "jbiport.h"
+
+#if PORT == WINDOWS
+#include
+#else
+typedef int BOOL;
+typedef unsigned char BYTE;
+typedef unsigned short WORD;
+#if PORT == EMBEDDED
+typedef unsigned int DWORD;
+#else
+typedef unsigned long DWORD;
+#endif
+#define TRUE 1
+#define FALSE 0
+#endif
+
+#if PORT != EMBEDDED
+#include
+#include
+#include
+#include
+#include
+#include
+#endif
+
+#include
+
+#include "jbiexprt.h"
+#include "jbistub.h"
+
+#if defined(USE_STATIC_MEMORY)
+ #define N_STATIC_MEMORY_KBYTES ((unsigned int) USE_STATIC_MEMORY)
+ #define N_STATIC_MEMORY_BYTES (N_STATIC_MEMORY_KBYTES * 1024)
+ #define POINTER_ALIGNMENT sizeof(DWORD)
+#else /* USE_STATIC_MEMORY */
+ /* #include */
+ #define POINTER_ALIGNMENT sizeof(BYTE)
+#endif /* USE_STATIC_MEMORY */
+
+#if PORT != EMBEDDED
+#include
+#include
+#include
+#include
+#include
+#endif
+
+#if PORT == DOS
+#include
+#endif
+
+int jbi_debug_level = DEBUG_NONE;
+static long jbi_delay_us = 0, jbi_delay_count = 0, jbi_peak_us = 0;
+
+void __jbi_jtag_udelay(unsigned long us)
+{
+ udelay(us);
+}
+void jbi_jtag_udelay(unsigned long us) __attribute__((weak, alias("__jbi_jtag_udelay")));
+
+#if PORT == WINDOWS
+#define PGDC_IOCTL_GET_DEVICE_INFO_PP 0x00166A00L
+#define PGDC_IOCTL_READ_PORT_PP 0x00166A04L
+#define PGDC_IOCTL_WRITE_PORT_PP 0x0016AA08L
+#define PGDC_IOCTL_PROCESS_LIST_PP 0x0016AA1CL
+#define PGDC_READ_INFO 0x0a80
+#define PGDC_READ_PORT 0x0a81
+#define PGDC_WRITE_PORT 0x0a82
+#define PGDC_PROCESS_LIST 0x0a87
+#define PGDC_HDLC_NTDRIVER_VERSION 2
+#define PORT_IO_BUFFER_SIZE 256
+#endif
+
+#if PORT == WINDOWS
+#ifdef __BORLANDC__
+/* create dummy inp() and outp() functions for Borland 32-bit compile */
+WORD inp(WORD address) { address = address; return(0); }
+void outp(WORD address, WORD data) { address = address; data = data; }
+#else
+#pragma intrinsic (inp, outp)
+#endif
+#endif
+
+/*
+* For Borland C compiler (16-bit), set the stack size
+*/
+#if PORT == DOS
+#ifdef __BORLANDC__
+extern unsigned int _stklen = 50000;
+#endif
+#endif
+
+/************************************************************************
+*
+* Global variables
+*/
+
+/* file buffer for Jam STAPL ByteCode input file */
+#if PORT == DOS
+unsigned char **file_buffer = NULL;
+#else
+unsigned char *file_buffer = NULL;
+#endif
+long file_pointer = 0L;
+long file_length = 0L;
+
+/* delay count for one millisecond delay */
+long one_ms_delay = 0L;
+
+/* serial port interface available on all platforms */
+BOOL jtag_hardware_initialized = FALSE;
+char *serial_port_name = NULL;
+BOOL specified_com_port = FALSE;
+int com_port = -1;
+void initialize_jtag_hardware(void);
+void close_jtag_hardware(void);
+
+#if defined(USE_STATIC_MEMORY)
+ unsigned char static_memory_heap[N_STATIC_MEMORY_BYTES] = { 0 };
+#endif /* USE_STATIC_MEMORY */
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ unsigned int n_bytes_allocated = 0;
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+#if defined(MEM_TRACKER)
+ unsigned int peak_memory_usage = 0;
+ unsigned int peak_allocations = 0;
+ unsigned int n_allocations = 0;
+#if defined(USE_STATIC_MEMORY)
+ unsigned int n_bytes_not_recovered = 0;
+#endif /* USE_STATIC_MEMORY */
+ const DWORD BEGIN_GUARD = 0x01234567;
+ const DWORD END_GUARD = 0x76543210;
+#endif /* MEM_TRACKER */
+
+#if PORT == WINDOWS || PORT == DOS
+/* parallel port interface available on PC only */
+BOOL specified_lpt_port = FALSE;
+BOOL specified_lpt_addr = FALSE;
+int lpt_port = 1;
+int initial_lpt_ctrl = 0;
+WORD lpt_addr = 0x3bc;
+WORD lpt_addr_table[3] = { 0x3bc, 0x378, 0x278 };
+BOOL alternative_cable_l = FALSE;
+BOOL alternative_cable_x = FALSE;
+void write_byteblaster(int port, int data);
+int read_byteblaster(int port);
+#endif
+
+#if PORT==WINDOWS
+#ifndef __BORLANDC__
+WORD lpt_addresses_from_registry[4] = { 0 };
+#endif
+#endif
+
+#if PORT == WINDOWS
+/* variables to manage cached I/O under Windows NT */
+BOOL windows_nt = FALSE;
+int port_io_count = 0;
+HANDLE nt_device_handle = INVALID_HANDLE_VALUE;
+struct PORT_IO_LIST_STRUCT
+{
+ USHORT command;
+ USHORT data;
+} port_io_buffer[PORT_IO_BUFFER_SIZE];
+extern void flush_ports(void);
+BOOL initialize_nt_driver(void);
+#endif
+
+/* function prototypes to allow forward reference */
+extern void delay_loop(long count);
+
+/*
+* This structure stores information about each available vector signal
+*/
+struct VECTOR_LIST_STRUCT
+{
+ char *signal_name;
+ int hardware_bit;
+ int vector_index;
+};
+
+struct VECTOR_LIST_STRUCT vector_list[] =
+{
+ /* add a record here for each vector signal */
+ { "", 0, -1 }
+};
+
+#define VECTOR_SIGNAL_COUNT ((int)(sizeof(vector_list)/sizeof(vector_list[0])))
+
+BOOL verbose = FALSE;
+
+/************************************************************************
+*
+* Customized interface functions for Jam STAPL ByteCode Player I/O:
+*
+* jbi_jtag_io()
+* jbi_message()
+* jbi_delay()
+*/
+
+int jbi_jtag_io(int tms, int tdi, int read_tdo)
+{
+#if PORT == WINDOWS || PORT == DOS
+ int data = 0;
+#endif
+ int tdo = 0;
+ int i = 0;
+ int result = 0;
+ char ch_data = 0;
+
+ if (!jtag_hardware_initialized)
+ {
+ initialize_jtag_hardware();
+ jtag_hardware_initialized = TRUE;
+ }
+
+ if (specified_com_port)
+ {
+ ch_data = (char)
+ ((tdi ? 0x01 : 0) | (tms ? 0x02 : 0) | 0x60);
+
+ write(com_port, &ch_data, 1);
+
+ if (read_tdo)
+ {
+ ch_data = 0x7e;
+ write(com_port, &ch_data, 1);
+ for (i = 0; (i < 100) && (result != 1); ++i)
+ {
+ result = read(com_port, &ch_data, 1);
+ }
+ if (result == 1)
+ {
+ tdo = ch_data & 0x01;
+ }
+ else
+ {
+ fprintf(stderr, "Error: BitBlaster not responding\n");
+ }
+ }
+
+ ch_data = (char)
+ ((tdi ? 0x01 : 0) | (tms ? 0x02 : 0) | 0x64);
+
+ write(com_port, &ch_data, 1);
+ }
+ else
+ {
+#if PORT == WINDOWS || PORT == DOS
+ data = (alternative_cable_l ? ((tdi ? 0x01 : 0) | (tms ? 0x04 : 0)) :
+ (alternative_cable_x ? ((tdi ? 0x01 : 0) | (tms ? 0x04 : 0) | 0x10) :
+ ((tdi ? 0x40 : 0) | (tms ? 0x02 : 0))));
+
+ write_byteblaster(0, data);
+
+ if (read_tdo)
+ {
+ tdo = read_byteblaster(1);
+ tdo = (alternative_cable_l ? ((tdo & 0x40) ? 1 : 0) :
+ (alternative_cable_x ? ((tdo & 0x10) ? 1 : 0) :
+ ((tdo & 0x80) ? 0 : 1)));
+ }
+
+ write_byteblaster(0, data | (alternative_cable_l ? 0x02 : (alternative_cable_x ? 0x02: 0x01)));
+
+ write_byteblaster(0, data);
+#elif PORT == EMBEDDED
+ /* Output variables TDI, TMS to the corresponding pin; As read_tdo, return the corresponding pin to the variable tdo */
+ tdo = jbi_jtag_io_(tms, tdi, read_tdo);
+#else
+ /* parallel port interface not available */
+ tdo = 0;
+#endif
+ }
+
+ return (tdo);
+}
+
+void jbi_message(char *message_text)
+{
+ puts(message_text);
+ puts("\n");
+ fflush(stdout);
+}
+
+void jbi_export_integer(char *key, long value)
+{
+ if (verbose)
+ {
+ printf("Export: key = \"%s\", value = %ld\n", key, value);
+ fflush(stdout);
+ }
+}
+
+#define HEX_LINE_CHARS 72
+#define HEX_LINE_BITS (HEX_LINE_CHARS * 4)
+
+char conv_to_hex(unsigned long value)
+{
+ char c;
+
+ if (value > 9)
+ {
+ c = (char) (value + ('A' - 10));
+ }
+ else
+ {
+ c = (char) (value + '0');
+ }
+
+ return (c);
+}
+
+void jbi_export_boolean_array(char *key, unsigned char *data, long count)
+{
+ char string[HEX_LINE_CHARS + 1];
+ long i, offset;
+ unsigned long size, line, lines, linebits, value, j, k;
+
+ if (verbose)
+ {
+ if (count > HEX_LINE_BITS)
+ {
+ printf("Export: key = \"%s\", %ld bits, value = HEX\n", key, count);
+ lines = (count + (HEX_LINE_BITS - 1)) / HEX_LINE_BITS;
+
+ for (line = 0; line < lines; ++line)
+ {
+ if (line < (lines - 1))
+ {
+ linebits = HEX_LINE_BITS;
+ size = HEX_LINE_CHARS;
+ offset = count - ((line + 1) * HEX_LINE_BITS);
+ }
+ else
+ {
+ linebits = count - ((lines - 1) * HEX_LINE_BITS);
+ size = (linebits + 3) / 4;
+ offset = 0L;
+ }
+
+ string[size] = '\0';
+ j = size - 1;
+ value = 0;
+
+ for (k = 0; k < linebits; ++k)
+ {
+ i = k + offset;
+ if (data[i >> 3] & (1 << (i & 7))) value |= (1 << (i & 3));
+ if ((i & 3) == 3)
+ {
+ string[j] = conv_to_hex(value);
+ value = 0;
+ --j;
+ }
+ }
+ if ((k & 3) > 0) string[j] = conv_to_hex(value);
+
+ printf("%s\n", string);
+ }
+
+ fflush(stdout);
+ }
+ else
+ {
+ size = (count + 3) / 4;
+ string[size] = '\0';
+ j = size - 1;
+ value = 0;
+
+ for (i = 0; i < count; ++i)
+ {
+ if (data[i >> 3] & (1 << (i & 7))) value |= (1 << (i & 3));
+ if ((i & 3) == 3)
+ {
+ string[j] = conv_to_hex(value);
+ value = 0;
+ --j;
+ }
+ }
+ if ((i & 3) > 0) string[j] = conv_to_hex(value);
+
+ printf("Export: key = \"%s\", %ld bits, value = HEX %s\n",
+ key, count, string);
+ fflush(stdout);
+ }
+ }
+}
+
+void jbi_delay(long microseconds)
+{
+ if (jbi_peak_us < microseconds) {
+ jbi_peak_us = microseconds;
+ }
+ jbi_delay_us += microseconds;
+ jbi_delay_count++;
+
+#if PORT == WINDOWS
+ /* if Windows NT, flush I/O cache buffer before delay loop */
+ if (windows_nt && (port_io_count > 0)) flush_ports();
+#endif
+
+#if PORT == EMBEDDED
+ udelay(microseconds);
+#else
+ delay_loop(microseconds *
+ ((one_ms_delay / 1000L) + ((one_ms_delay % 1000L) ? 1 : 0)));
+#endif
+}
+
+int jbi_vector_map
+(
+ int signal_count,
+ char **signals
+)
+{
+ int signal, vector, ch_index, diff;
+ int matched_count = 0;
+ char l, r;
+
+ for (vector = 0; (vector < VECTOR_SIGNAL_COUNT); ++vector)
+ {
+ vector_list[vector].vector_index = -1;
+ }
+
+ for (signal = 0; signal < signal_count; ++signal)
+ {
+ diff = 1;
+ for (vector = 0; (diff != 0) && (vector < VECTOR_SIGNAL_COUNT);
+ ++vector)
+ {
+ if (vector_list[vector].vector_index == -1)
+ {
+ ch_index = 0;
+ do
+ {
+ l = signals[signal][ch_index];
+ r = vector_list[vector].signal_name[ch_index];
+ diff = (((l >= 'a') && (l <= 'z')) ? (l - ('a' - 'A')) : l)
+ - (((r >= 'a') && (r <= 'z')) ? (r - ('a' - 'A')) : r);
+ ++ch_index;
+ }
+ while ((diff == 0) && (l != '\0') && (r != '\0'));
+
+ if (diff == 0)
+ {
+ vector_list[vector].vector_index = signal;
+ ++matched_count;
+ }
+ }
+ }
+ }
+
+ return (matched_count);
+}
+
+int jbi_vector_io
+(
+ int signal_count,
+ long *dir_vect,
+ long *data_vect,
+ long *capture_vect
+)
+{
+ int signal, vector, bit;
+ int matched_count = 0;
+ int data = 0;
+ int mask = 0;
+ int dir = 0;
+ int i = 0;
+ int result = 0;
+ char ch_data = 0;
+
+ if (!jtag_hardware_initialized)
+ {
+ initialize_jtag_hardware();
+ jtag_hardware_initialized = TRUE;
+ }
+
+ /*
+ * Collect information about output signals
+ */
+ for (vector = 0; vector < VECTOR_SIGNAL_COUNT; ++vector)
+ {
+ signal = vector_list[vector].vector_index;
+
+ if ((signal >= 0) && (signal < signal_count))
+ {
+ bit = (1 << vector_list[vector].hardware_bit);
+
+ mask |= bit;
+ if (data_vect[signal >> 5] & (1L << (signal & 0x1f))) data |= bit;
+ if (dir_vect[signal >> 5] & (1L << (signal & 0x1f))) dir |= bit;
+
+ ++matched_count;
+ }
+ }
+
+ /*
+ * Write outputs to hardware interface, if any
+ */
+ if (dir != 0)
+ {
+ if (specified_com_port)
+ {
+ ch_data = (char) (((data >> 6) & 0x01) | (data & 0x02) |
+ ((data << 2) & 0x04) | ((data << 3) & 0x08) | 0x60);
+ write(com_port, &ch_data, 1);
+ }
+ else
+ {
+#if PORT == WINDOWS || PORT == DOS
+
+ write_byteblaster(0, data);
+
+#endif
+ }
+ }
+
+ /*
+ * Read the input signals and save information in capture_vect[]
+ */
+ if ((dir != mask) && (capture_vect != NULL))
+ {
+ if (specified_com_port)
+ {
+ ch_data = 0x7e;
+ write(com_port, &ch_data, 1);
+ for (i = 0; (i < 100) && (result != 1); ++i)
+ {
+ result = read(com_port, &ch_data, 1);
+ }
+ if (result == 1)
+ {
+ data = ((ch_data << 7) & 0x80) | ((ch_data << 3) & 0x10);
+ }
+ else
+ {
+ fprintf(stderr, "Error: BitBlaster not responding\n");
+ }
+ }
+ else
+ {
+#if PORT == WINDOWS || PORT == DOS
+
+ data = read_byteblaster(1) ^ 0x80; /* parallel port inverts bit 7 */
+
+#endif
+ }
+
+ for (vector = 0; vector < VECTOR_SIGNAL_COUNT; ++vector)
+ {
+ signal = vector_list[vector].vector_index;
+
+ if ((signal >= 0) && (signal < signal_count))
+ {
+ bit = (1 << vector_list[vector].hardware_bit);
+
+ if ((dir & bit) == 0) /* if it is an input signal... */
+ {
+ if (data & bit)
+ {
+ capture_vect[signal >> 5] |= (1L << (signal & 0x1f));
+ }
+ else
+ {
+ capture_vect[signal >> 5] &= ~(unsigned long)
+ (1L << (signal & 0x1f));
+ }
+ }
+ }
+ }
+ }
+
+ return (matched_count);
+}
+
+void *jbi_malloc(unsigned int size)
+{
+ unsigned int n_bytes_to_allocate =
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ sizeof(unsigned int) +
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+#if defined(MEM_TRACKER)
+ (2 * sizeof(DWORD)) +
+#endif /* MEM_TRACKER */
+ (POINTER_ALIGNMENT * ((size + POINTER_ALIGNMENT - 1) / POINTER_ALIGNMENT));
+
+ unsigned char *ptr = 0;
+
+#if defined(MEM_TRACKER)
+ if ((n_bytes_allocated + n_bytes_to_allocate) > peak_memory_usage)
+ {
+ peak_memory_usage = n_bytes_allocated + n_bytes_to_allocate;
+ }
+ if ((n_allocations + 1) > peak_allocations)
+ {
+ peak_allocations = n_allocations + 1;
+ }
+#endif /* MEM_TRACKER */
+
+#if defined(USE_STATIC_MEMORY)
+ if ((n_bytes_allocated + n_bytes_to_allocate) <= N_STATIC_MEMORY_BYTES)
+ {
+ ptr = (&(static_memory_heap[n_bytes_allocated]));
+ }
+#else /* USE_STATIC_MEMORY */
+ ptr = (unsigned char *) malloc(n_bytes_to_allocate);
+#endif /* USE_STATIC_MEMORY */
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ if (ptr != 0)
+ {
+ unsigned int i = 0;
+
+#if defined(MEM_TRACKER)
+ for (i = 0; i < sizeof(DWORD); ++i)
+ {
+ *ptr = (unsigned char) (BEGIN_GUARD >> (8 * i));
+ ++ptr;
+ }
+#endif /* MEM_TRACKER */
+
+ for (i = 0; i < sizeof(unsigned int); ++i)
+ {
+ *ptr = (unsigned char) (size >> (8 * i));
+ ++ptr;
+ }
+
+#if defined(MEM_TRACKER)
+ for (i = 0; i < sizeof(DWORD); ++i)
+ {
+ *(ptr + size + i) = (unsigned char) (END_GUARD >> (8 * i));
+ /* don't increment ptr */
+ }
+
+ ++n_allocations;
+#endif /* MEM_TRACKER */
+
+ n_bytes_allocated += n_bytes_to_allocate;
+ }
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+ jbi_dbg(DEBUG_MM, "malloc 0x%p(%d,%d)\n", ptr, size, n_bytes_to_allocate);
+
+ return ptr;
+}
+
+void jbi_free(void *ptr)
+{
+ jbi_dbg(DEBUG_MM, "free 0x%p\n", ptr);
+
+ if
+ (
+#if defined(MEM_TRACKER)
+ (n_allocations > 0) &&
+#endif /* MEM_TRACKER */
+ (ptr != 0)
+ )
+ {
+ unsigned char *tmp_ptr = (unsigned char *) ptr;
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ unsigned int n_bytes_to_free = 0;
+ unsigned int i = 0;
+ unsigned int size = 0;
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+#if defined(MEM_TRACKER)
+ DWORD begin_guard = 0;
+ DWORD end_guard = 0;
+
+ tmp_ptr -= sizeof(DWORD);
+#endif /* MEM_TRACKER */
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ tmp_ptr -= sizeof(unsigned int);
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+ ptr = tmp_ptr;
+
+#if defined(MEM_TRACKER)
+ for (i = 0; i < sizeof(DWORD); ++i)
+ {
+ begin_guard |= (((DWORD)(*tmp_ptr)) << (8 * i));
+ ++tmp_ptr;
+ }
+#endif /* MEM_TRACKER */
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ for (i = 0; i < sizeof(unsigned int); ++i)
+ {
+ size |= (((unsigned int)(*tmp_ptr)) << (8 * i));
+ ++tmp_ptr;
+ }
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+#if defined(MEM_TRACKER)
+ tmp_ptr += size;
+
+ for (i = 0; i < sizeof(DWORD); ++i)
+ {
+ end_guard |= (((DWORD)(*tmp_ptr)) << (8 * i));
+ ++tmp_ptr;
+ }
+
+ if ((begin_guard != BEGIN_GUARD) || (end_guard != END_GUARD))
+ {
+ fprintf(stderr, "Error: memory corruption detected for allocation #%d... bad %s guard\n",
+ n_allocations, (begin_guard != BEGIN_GUARD) ? "begin" : "end");
+ }
+
+ --n_allocations;
+#endif /* MEM_TRACKER */
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ n_bytes_to_free =
+#if defined(MEM_TRACKER)
+ (2 * sizeof(DWORD)) +
+#endif /* MEM_TRACKER */
+ sizeof(unsigned int) +
+ (POINTER_ALIGNMENT * ((size + POINTER_ALIGNMENT - 1) / POINTER_ALIGNMENT));
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+#if defined(USE_STATIC_MEMORY)
+ if ((((unsigned long) ptr - (unsigned long) static_memory_heap) + n_bytes_to_free) == (unsigned long) n_bytes_allocated)
+ {
+ n_bytes_allocated -= n_bytes_to_free;
+ }
+#if defined(MEM_TRACKER)
+ else
+ {
+ n_bytes_not_recovered += n_bytes_to_free;
+ }
+#endif /* MEM_TRACKER */
+#else /* USE_STATIC_MEMORY */
+#if defined(MEM_TRACKER)
+ n_bytes_allocated -= n_bytes_to_free;
+#endif /* MEM_TRACKER */
+ free(ptr);
+#endif /* USE_STATIC_MEMORY */
+ }
+#if defined(MEM_TRACKER)
+ else
+ {
+ if (ptr != 0)
+ {
+ fprintf(stderr, "Error: attempt to free unallocated memory\n");
+ }
+ }
+#endif /* MEM_TRACKER */
+}
+
+#if PORT == WINDOWS || PORT == DOS
+/************************************************************************
+*
+* get_tick_count() -- Get system tick count in milliseconds
+*
+* for DOS, use BIOS function _bios_timeofday()
+* for WINDOWS use GetTickCount() function
+* for UNIX use clock() system function
+*/
+DWORD get_tick_count(void)
+{
+ DWORD tick_count = 0L;
+
+#if PORT == WINDOWS
+ tick_count = GetTickCount();
+#elif PORT == DOS
+ _bios_timeofday(_TIME_GETCLOCK, (long *)&tick_count);
+ tick_count *= 55L; /* convert to milliseconds */
+#else
+ /* assume clock() function returns microseconds */
+ tick_count = (DWORD) (clock() / 1000L);
+#endif
+
+ return (tick_count);
+}
+#endif
+
+#define DELAY_SAMPLES 10
+#define DELAY_CHECK_LOOPS 10000
+
+void calibrate_delay(void)
+{
+#if PORT == WINDOWS || PORT == DOS
+ int sample = 0;
+ int count = 0;
+ DWORD tick_count1 = 0L;
+ DWORD tick_count2 = 0L;
+#endif
+
+ one_ms_delay = 0L;
+
+#if PORT == WINDOWS || PORT == DOS
+ for (sample = 0; sample < DELAY_SAMPLES; ++sample)
+ {
+ count = 0;
+ tick_count1 = get_tick_count();
+ while ((tick_count2 = get_tick_count()) == tick_count1) {};
+ do { delay_loop(DELAY_CHECK_LOOPS); count++; } while
+ ((tick_count1 = get_tick_count()) == tick_count2);
+ one_ms_delay += ((DELAY_CHECK_LOOPS * (DWORD)count) /
+ (tick_count1 - tick_count2));
+ }
+
+ one_ms_delay /= DELAY_SAMPLES;
+#else
+ /* This is system-dependent! Update this number for target system */
+ one_ms_delay = 1000L;
+#endif
+}
+
+char *error_text[] =
+{
+/* JBIC_SUCCESS 0 */ "success",
+/* JBIC_OUT_OF_MEMORY 1 */ "out of memory",
+/* JBIC_IO_ERROR 2 */ "file access error",
+/* JAMC_SYNTAX_ERROR 3 */ "syntax error",
+/* JBIC_UNEXPECTED_END 4 */ "unexpected end of file",
+/* JBIC_UNDEFINED_SYMBOL 5 */ "undefined symbol",
+/* JAMC_REDEFINED_SYMBOL 6 */ "redefined symbol",
+/* JBIC_INTEGER_OVERFLOW 7 */ "integer overflow",
+/* JBIC_DIVIDE_BY_ZERO 8 */ "divide by zero",
+/* JBIC_CRC_ERROR 9 */ "CRC mismatch",
+/* JBIC_INTERNAL_ERROR 10 */ "internal error",
+/* JBIC_BOUNDS_ERROR 11 */ "bounds error",
+/* JAMC_TYPE_MISMATCH 12 */ "type mismatch",
+/* JAMC_ASSIGN_TO_CONST 13 */ "assignment to constant",
+/* JAMC_NEXT_UNEXPECTED 14 */ "NEXT unexpected",
+/* JAMC_POP_UNEXPECTED 15 */ "POP unexpected",
+/* JAMC_RETURN_UNEXPECTED 16 */ "RETURN unexpected",
+/* JAMC_ILLEGAL_SYMBOL 17 */ "illegal symbol name",
+/* JBIC_VECTOR_MAP_FAILED 18 */ "vector signal name not found",
+/* JBIC_USER_ABORT 19 */ "execution cancelled",
+/* JBIC_STACK_OVERFLOW 20 */ "stack overflow",
+/* JBIC_ILLEGAL_OPCODE 21 */ "illegal instruction code",
+/* JAMC_PHASE_ERROR 22 */ "phase error",
+/* JAMC_SCOPE_ERROR 23 */ "scope error",
+/* JBIC_ACTION_NOT_FOUND 24 */ "action not found",
+};
+
+#define MAX_ERROR_CODE (int)(sizeof(error_text)/sizeof(error_text[0]))
+
+/************************************************************************/
+
+#if 0
+int main(int argc, char **argv)
+{
+ BOOL help = FALSE;
+ BOOL error = FALSE;
+ char *filename = NULL;
+ long offset = 0L;
+ long error_address = 0L;
+ JBI_RETURN_TYPE crc_result = JBIC_SUCCESS;
+ JBI_RETURN_TYPE exec_result = JBIC_SUCCESS;
+ unsigned short expected_crc = 0;
+ unsigned short actual_crc = 0;
+ char key[33] = {0};
+ char value[257] = {0};
+ int exit_status = 0;
+ int arg = 0;
+ int exit_code = 0;
+ int format_version = 0;
+ time_t start_time = 0;
+ time_t end_time = 0;
+ int time_delta = 0;
+ char *workspace = NULL;
+ char *action = NULL;
+ char *init_list[10];
+ int init_count = 0;
+ FILE *fp = NULL;
+ struct stat sbuf;
+ long workspace_size = 0;
+ char *exit_string = NULL;
+ int reset_jtag = 1;
+ int execute_program = 1;
+ int action_count = 0;
+ int procedure_count = 0;
+ int index = 0;
+ char *action_name = NULL;
+ char *description = NULL;
+ JBI_PROCINFO *procedure_list = NULL;
+ JBI_PROCINFO *procptr = NULL;
+
+ verbose = FALSE;
+
+ init_list[0] = NULL;
+
+ /* print out the version string and copyright message */
+ fprintf(stderr, "Jam STAPL ByteCode Player Version 2.2\nCopyright (C) 1998-2001 Altera Corporation\n\n");
+
+ for (arg = 1; arg < argc; arg++)
+ {
+#if PORT == UNIX
+ if (argv[arg][0] == '-')
+#else
+ if ((argv[arg][0] == '-') || (argv[arg][0] == '/'))
+#endif
+ {
+ switch(toupper(argv[arg][1]))
+ {
+ case 'A': /* set action name */
+ if (action == NULL)
+ {
+ action = &argv[arg][2];
+ }
+ else
+ {
+ error = TRUE;
+ }
+ break;
+
+#if PORT == WINDOWS || PORT == DOS
+ case 'C': /* Use alternative ISP download cable */
+ if(toupper(argv[arg][2]) == 'L')
+ alternative_cable_l = TRUE;
+ else if(toupper(argv[arg][2]) == 'X')
+ alternative_cable_x = TRUE;
+ break;
+#endif
+
+ case 'D': /* initialization list */
+ if (argv[arg][2] == '"')
+ {
+ init_list[init_count] = &argv[arg][3];
+ }
+ else
+ {
+ init_list[init_count] = &argv[arg][2];
+ }
+ init_list[++init_count] = NULL;
+ break;
+
+#if PORT == WINDOWS || PORT == DOS
+ case 'P': /* set LPT port address */
+ specified_lpt_port = TRUE;
+ if (sscanf(&argv[arg][2], "%d", &lpt_port) != 1) error = TRUE;
+ if ((lpt_port < 1) || (lpt_port > 3)) error = TRUE;
+ if (error)
+ {
+ if (sscanf(&argv[arg][2], "%x", &lpt_port) == 1)
+ {
+ if ((lpt_port == 0x3bc) ||
+ (lpt_port == 0x378) ||
+ (lpt_port == 0x278))
+ {
+ error = FALSE;
+ specified_lpt_addr = TRUE;
+ lpt_addr = (WORD) lpt_port;
+ lpt_port = 1;
+ }
+ }
+ }
+ break;
+#endif
+
+ case 'R': /* don't reset the JTAG chain after use */
+ reset_jtag = 0;
+ break;
+
+ case 'S': /* set serial port address */
+ serial_port_name = &argv[arg][2];
+ specified_com_port = TRUE;
+ break;
+
+ case 'M': /* set memory size */
+ if (sscanf(&argv[arg][2], "%ld", &workspace_size) != 1)
+ error = TRUE;
+ if (workspace_size == 0) error = TRUE;
+ break;
+
+ case 'H': /* help */
+ help = TRUE;
+ break;
+
+ case 'V': /* verbose */
+ verbose = TRUE;
+ break;
+
+ case 'I': /* show info only, do not execute */
+ verbose = TRUE;
+ execute_program = 0;
+ break;
+
+ default:
+ error = TRUE;
+ break;
+ }
+ }
+ else
+ {
+ /* it's a filename */
+ if (filename == NULL)
+ {
+ filename = argv[arg];
+ }
+ else
+ {
+ /* error -- we already found a filename */
+ error = TRUE;
+ }
+ }
+
+ if (error)
+ {
+ fprintf(stderr, "Illegal argument: \"%s\"\n", argv[arg]);
+ help = TRUE;
+ error = FALSE;
+ }
+ }
+
+#if PORT == WINDOWS || PORT == DOS
+ if (specified_lpt_port && specified_com_port)
+ {
+ fprintf(stderr, "Error: -s and -p options may not be used together\n\n");
+ help = TRUE;
+ }
+#endif
+
+ if (help || (filename == NULL))
+ {
+ fprintf(stderr, "Usage: jbi [options] \n");
+ fprintf(stderr, "\nAvailable options:\n");
+ fprintf(stderr, " -h : show help message\n");
+ fprintf(stderr, " -v : show verbose messages\n");
+ fprintf(stderr, " -i : show file info only - does not execute any action\n");
+ fprintf(stderr, " -a : specify an action name (Jam STAPL)\n");
+ fprintf(stderr, " -d : initialize variable to specified value (Jam 1.1)\n");
+ fprintf(stderr, " -d : enable optional procedure (Jam STAPL)\n");
+ fprintf(stderr, " -d : disable recommended procedure (Jam STAPL)\n");
+#if PORT == WINDOWS || PORT == DOS
+ fprintf(stderr, " -p : parallel port number or address (for ByteBlaster)\n");
+ fprintf(stderr, " -c : alternative download cable compatibility: -cl or -cx\n");
+#endif
+ fprintf(stderr, " -s : serial port name (for BitBlaster)\n");
+ fprintf(stderr, " -r : don't reset JTAG TAP after use\n");
+ exit_status = 1;
+ }
+ else if ((workspace_size > 0) &&
+ ((workspace = (char *) jbi_malloc((size_t) workspace_size)) == NULL))
+ {
+ fprintf(stderr, "Error: can't allocate memory (%d Kbytes)\n",
+ (int) (workspace_size / 1024L));
+ exit_status = 1;
+ }
+ else if (access(filename, 0) != 0)
+ {
+ fprintf(stderr, "Error: can't access file \"%s\"\n", filename);
+ exit_status = 1;
+ }
+ else
+ {
+ /* get length of file */
+ if (stat(filename, &sbuf) == 0) file_length = sbuf.st_size;
+
+ if ((fp = fopen(filename, "rb")) == NULL)
+ {
+ fprintf(stderr, "Error: can't open file \"%s\"\n", filename);
+ exit_status = 1;
+ }
+ else
+ {
+ /*
+ * Read entire file into a buffer
+ */
+#if PORT == DOS
+ int pages = 1 + (int) (file_length >> 14L);
+ int page;
+ file_buffer = (unsigned char **) jbi_malloc(
+ (size_t) (pages * sizeof(char *)));
+
+ for (page = 0; page < pages; ++page)
+ {
+ /* allocate enough 16K blocks to store the file */
+ file_buffer[page] = (unsigned char *) jbi_malloc (0x4000);
+ if (file_buffer[page] == NULL)
+ {
+ /* flag error and break out of loop */
+ file_buffer = NULL;
+ page = pages;
+ }
+ }
+#else
+ file_buffer = (unsigned char *) jbi_malloc((size_t) file_length);
+#endif
+
+ if (file_buffer == NULL)
+ {
+ fprintf(stderr, "Error: can't allocate memory (%d Kbytes)\n",
+ (int) (file_length / 1024L));
+ exit_status = 1;
+ }
+ else
+ {
+#if PORT == DOS
+ int pages = 1 + (int) (file_length >> 14L);
+ int page;
+ size_t page_size = 0x4000;
+ for (page = 0; (page < pages) && (exit_status == 0); ++page)
+ {
+ if (page == (pages - 1))
+ {
+ /* last page may not be full 16K bytes */
+ page_size = (size_t) (file_length & 0x3fffL);
+ }
+ if (fread(file_buffer[page], 1, page_size, fp) != page_size)
+ {
+ fprintf(stderr, "Error reading file \"%s\"\n", filename);
+ exit_status = 1;
+ }
+ }
+#else
+ if (fread(file_buffer, 1, (size_t) file_length, fp) !=
+ (size_t) file_length)
+ {
+ fprintf(stderr, "Error reading file \"%s\"\n", filename);
+ exit_status = 1;
+ }
+#endif
+ }
+
+ fclose(fp);
+ }
+
+ if (exit_status == 0)
+ {
+ /*
+ * Get Operating System type
+ */
+#if PORT == WINDOWS
+ windows_nt = !(GetVersion() & 0x80000000);
+#endif
+
+ /*
+ * Calibrate the delay loop function
+ */
+ calibrate_delay();
+
+ /*
+ * Check CRC
+ */
+ crc_result = jbi_check_crc(file_buffer, file_length,
+ &expected_crc, &actual_crc);
+
+ if (verbose || (crc_result == JBIC_CRC_ERROR))
+ {
+ switch (crc_result)
+ {
+ case JBIC_SUCCESS:
+ printf("CRC matched: CRC value = %04X\n", actual_crc);
+ break;
+
+ case JBIC_CRC_ERROR:
+ printf("CRC mismatch: expected %04X, actual %04X\n",
+ expected_crc, actual_crc);
+ break;
+
+ case JBIC_UNEXPECTED_END:
+ printf("Expected CRC not found, actual CRC value = %04X\n",
+ actual_crc);
+ break;
+
+ case JBIC_IO_ERROR:
+ printf("Error: File format is not recognized.\n");
+ exit(1);
+ break;
+
+ default:
+ printf("CRC function returned error code %d\n", crc_result);
+ break;
+ }
+ }
+
+ if (verbose)
+ {
+ /*
+ * Display file format version
+ */
+ jbi_get_file_info(file_buffer, file_length,
+ &format_version, &action_count, &procedure_count);
+
+ printf("File format is %s ByteCode format\n",
+ (format_version == 2) ? "Jam STAPL" : "pre-standardized Jam 1.1");
+
+ /*
+ * Dump out NOTE fields
+ */
+ while (jbi_get_note(file_buffer, file_length,
+ &offset, key, value, 256) == 0)
+ {
+ printf("NOTE \"%s\" = \"%s\"\n", key, value);
+ }
+
+ /*
+ * Dump the action table
+ */
+ if ((format_version == 2) && (action_count > 0))
+ {
+ printf("\nActions available in this file:\n");
+
+ for (index = 0; index < action_count; ++index)
+ {
+ jbi_get_action_info(file_buffer, file_length,
+ index, &action_name, &description, &procedure_list);
+
+ if (description == NULL)
+ {
+ printf("%s\n", action_name);
+ }
+ else
+ {
+ printf("%s \"%s\"\n", action_name, description);
+ }
+
+#if PORT == DOS
+ if (action_name != NULL) jbi_free(action_name);
+ if (description != NULL) jbi_free(description);
+#endif
+
+ procptr = procedure_list;
+ while (procptr != NULL)
+ {
+ if (procptr->attributes != 0)
+ {
+ printf(" %s (%s)\n", procptr->name,
+ (procptr->attributes == 1) ?
+ "optional" : "recommended");
+ }
+
+#if PORT == DOS
+ if (procptr->name != NULL) jbi_free(procptr->name);
+#endif
+
+ procedure_list = procptr->next;
+ jbi_free(procptr);
+ procptr = procedure_list;
+ }
+ }
+
+ /* add a blank line before execution messages */
+ if (execute_program) printf("\n");
+ }
+ }
+
+ if (execute_program)
+ {
+ /*
+ * Execute the Jam STAPL ByteCode program
+ */
+ time(&start_time);
+ exec_result = jbi_execute(file_buffer, file_length, workspace,
+ workspace_size, action, init_list, reset_jtag,
+ &error_address, &exit_code, &format_version);
+ time(&end_time);
+
+ if (exec_result == JBIC_SUCCESS)
+ {
+ if (format_version == 2)
+ {
+ switch (exit_code)
+ {
+ case 0: exit_string = "Success"; break;
+ case 1: exit_string = "Checking chain failure"; break;
+ case 2: exit_string = "Reading IDCODE failure"; break;
+ case 3: exit_string = "Reading USERCODE failure"; break;
+ case 4: exit_string = "Reading UESCODE failure"; break;
+ case 5: exit_string = "Entering ISP failure"; break;
+ case 6: exit_string = "Unrecognized device"; break;
+ case 7: exit_string = "Device revision is not supported"; break;
+ case 8: exit_string = "Erase failure"; break;
+ case 9: exit_string = "Device is not blank"; break;
+ case 10: exit_string = "Device programming failure"; break;
+ case 11: exit_string = "Device verify failure"; break;
+ case 12: exit_string = "Read failure"; break;
+ case 13: exit_string = "Calculating checksum failure"; break;
+ case 14: exit_string = "Setting security bit failure"; break;
+ case 15: exit_string = "Querying security bit failure"; break;
+ case 16: exit_string = "Exiting ISP failure"; break;
+ case 17: exit_string = "Performing system test failure"; break;
+ default: exit_string = "Unknown exit code"; break;
+ }
+ }
+ else
+ {
+ switch (exit_code)
+ {
+ case 0: exit_string = "Success"; break;
+ case 1: exit_string = "Illegal initialization values"; break;
+ case 2: exit_string = "Unrecognized device"; break;
+ case 3: exit_string = "Device revision is not supported"; break;
+ case 4: exit_string = "Device programming failure"; break;
+ case 5: exit_string = "Device is not blank"; break;
+ case 6: exit_string = "Device verify failure"; break;
+ case 7: exit_string = "SRAM configuration failure"; break;
+ default: exit_string = "Unknown exit code"; break;
+ }
+ }
+
+ printf("Exit code = %d... %s\n", exit_code, exit_string);
+ }
+ else if ((format_version == 2) &&
+ (exec_result == JBIC_ACTION_NOT_FOUND))
+ {
+ if ((action == NULL) || (*action == '\0'))
+ {
+ printf("Error: no action specified for Jam STAPL file.\nProgram terminated.\n");
+ }
+ else
+ {
+ printf("Error: action \"%s\" is not supported for this Jam STAPL file.\nProgram terminated.\n", action);
+ }
+ }
+ else if (exec_result < MAX_ERROR_CODE)
+ {
+ printf("Error at address %ld: %s.\nProgram terminated.\n",
+ error_address, error_text[exec_result]);
+ }
+ else
+ {
+ printf("Unknown error code %ld\n", exec_result);
+ }
+
+ /*
+ * Print out elapsed time
+ */
+ if (verbose)
+ {
+ time_delta = (int) (end_time - start_time);
+ printf("Elapsed time = %02u:%02u:%02u\n",
+ time_delta / 3600, /* hours */
+ (time_delta % 3600) / 60, /* minutes */
+ time_delta % 60); /* seconds */
+ }
+ }
+ }
+ }
+
+ if (jtag_hardware_initialized) close_jtag_hardware();
+
+ if (workspace != NULL) jbi_free(workspace);
+ if (file_buffer != NULL) jbi_free(file_buffer);
+
+#if defined(MEM_TRACKER)
+ if (verbose)
+ {
+#if defined(USE_STATIC_MEMORY)
+ fprintf(stdout, "Memory Usage Info: static memory size = %ud (%dKB)\n", N_STATIC_MEMORY_BYTES, N_STATIC_MEMORY_KBYTES);
+#endif /* USE_STATIC_MEMORY */
+ fprintf(stdout, "Memory Usage Info: peak memory usage = %ud (%dKB)\n", peak_memory_usage, (peak_memory_usage + 1023) / 1024);
+ fprintf(stdout, "Memory Usage Info: peak allocations = %d\n", peak_allocations);
+#if defined(USE_STATIC_MEMORY)
+ if ((n_bytes_allocated - n_bytes_not_recovered) != 0)
+ {
+ fprintf(stdout, "Memory Usage Info: bytes still allocated = %d (%dKB)\n", (n_bytes_allocated - n_bytes_not_recovered), ((n_bytes_allocated - n_bytes_not_recovered) + 1023) / 1024);
+ }
+#else /* USE_STATIC_MEMORY */
+ if (n_bytes_allocated != 0)
+ {
+ fprintf(stdout, "Memory Usage Info: bytes still allocated = %d (%dKB)\n", n_bytes_allocated, (n_bytes_allocated + 1023) / 1024);
+ }
+#endif /* USE_STATIC_MEMORY */
+ if (n_allocations != 0)
+ {
+ fprintf(stdout, "Memory Usage Info: allocations not freed = %d\n", n_allocations);
+ }
+ }
+#endif /* MEM_TRACKER */
+
+ return (exit_status);
+}
+#endif
+
+#if PORT==WINDOWS
+#ifndef __BORLANDC__
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+*
+* SEARCH_DYN_DATA
+*
+* Searches recursively in Windows 95/98 Registry for parallel port info
+* under HKEY_DYN_DATA registry key. Called by search_local_machine().
+*/
+void search_dyn_data
+(
+ char *dd_path,
+ char *hardware_key,
+ int lpt
+)
+{
+ DWORD index;
+ DWORD size;
+ DWORD type;
+ LONG result;
+ HKEY key;
+ int length;
+ WORD address;
+ char buffer[1024];
+ FILETIME last_write = {0};
+ WORD *word_ptr;
+ int i;
+
+ length = strlen(dd_path);
+
+ if (RegOpenKeyEx(
+ HKEY_DYN_DATA,
+ dd_path,
+ 0L,
+ KEY_READ,
+ &key)
+ == ERROR_SUCCESS)
+ {
+ size = 1023;
+
+ if (RegQueryValueEx(
+ key,
+ "HardWareKey",
+ NULL,
+ &type,
+ (unsigned char *) buffer,
+ &size)
+ == ERROR_SUCCESS)
+ {
+ if ((type == REG_SZ) && (stricmp(buffer, hardware_key) == 0))
+ {
+ size = 1023;
+
+ if (RegQueryValueEx(
+ key,
+ "Allocation",
+ NULL,
+ &type,
+ (unsigned char *) buffer,
+ &size)
+ == ERROR_SUCCESS)
+ {
+ /*
+ * By "inspection", I have found five cases: size 32, 48,
+ * 56, 60, and 80 bytes. The port address seems to be
+ * located at different offsets in the buffer for these
+ * five cases, as shown below. If a valid port address
+ * is not found, or the size is not one of these known
+ * sizes, then I search through the entire buffer and
+ * look for a value which is a valid port address.
+ */
+
+ word_ptr = (WORD *) buffer;
+
+ if ((type == REG_BINARY) && (size == 32))
+ {
+ address = word_ptr[10];
+ }
+ else if ((type == REG_BINARY) && (size == 48))
+ {
+ address = word_ptr[18];
+ }
+ else if ((type == REG_BINARY) && (size == 56))
+ {
+ address = word_ptr[22];
+ }
+ else if ((type == REG_BINARY) && (size == 60))
+ {
+ address = word_ptr[24];
+ }
+ else if ((type == REG_BINARY) && (size == 80))
+ {
+ address = word_ptr[24];
+ }
+ else address = 0;
+
+ /* if not found, search through entire buffer */
+ i = 0;
+ while ((i < (int) (size / 2)) &&
+ (address != 0x278) &&
+ (address != 0x27C) &&
+ (address != 0x378) &&
+ (address != 0x37C) &&
+ (address != 0x3B8) &&
+ (address != 0x3BC))
+ {
+ if ((word_ptr[i] == 0x278) ||
+ (word_ptr[i] == 0x27C) ||
+ (word_ptr[i] == 0x378) ||
+ (word_ptr[i] == 0x37C) ||
+ (word_ptr[i] == 0x3B8) ||
+ (word_ptr[i] == 0x3BC))
+ {
+ address = word_ptr[i];
+ }
+ ++i;
+ }
+
+ if ((address == 0x278) ||
+ (address == 0x27C) ||
+ (address == 0x378) ||
+ (address == 0x37C) ||
+ (address == 0x3B8) ||
+ (address == 0x3BC))
+ {
+ lpt_addresses_from_registry[lpt] = address;
+ }
+ }
+ }
+ }
+
+ index = 0;
+
+ do
+ {
+ size = 1023;
+
+ result = RegEnumKeyEx(
+ key,
+ index++,
+ buffer,
+ &size,
+ NULL,
+ NULL,
+ NULL,
+ &last_write);
+
+ if (result == ERROR_SUCCESS)
+ {
+ dd_path[length] = '\\';
+ dd_path[length + 1] = '\0';
+ strcpy(&dd_path[length + 1], buffer);
+
+ search_dyn_data(dd_path, hardware_key, lpt);
+
+ dd_path[length] = '\0';
+ }
+ }
+ while (result == ERROR_SUCCESS);
+
+ RegCloseKey(key);
+ }
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+*
+* SEARCH_LOCAL_MACHINE
+*
+* Searches recursively in Windows 95/98 Registry for parallel port info
+* under HKEY_LOCAL_MACHINE\Enum. When parallel port is found, calls
+* search_dyn_data() to get the port address.
+*/
+void search_local_machine
+(
+ char *lm_path,
+ char *dd_path
+)
+{
+ DWORD index;
+ DWORD size;
+ DWORD type;
+ LONG result;
+ HKEY key;
+ int length;
+ char buffer[1024];
+ FILETIME last_write = {0};
+
+ length = strlen(lm_path);
+
+ if (RegOpenKeyEx(
+ HKEY_LOCAL_MACHINE,
+ lm_path,
+ 0L,
+ KEY_READ,
+ &key)
+ == ERROR_SUCCESS)
+ {
+ size = 1023;
+
+ if (RegQueryValueEx(
+ key,
+ "PortName",
+ NULL,
+ &type,
+ (unsigned char *) buffer,
+ &size)
+ == ERROR_SUCCESS)
+ {
+ if ((type == REG_SZ) &&
+ (size == 5) &&
+ (buffer[0] == 'L') &&
+ (buffer[1] == 'P') &&
+ (buffer[2] == 'T') &&
+ (buffer[3] >= '1') &&
+ (buffer[3] <= '4') &&
+ (buffer[4] == '\0'))
+ {
+ /* we found the entry in HKEY_LOCAL_MACHINE, now we need to */
+ /* find the corresponding entry under HKEY_DYN_DATA. */
+ /* add 5 to lm_path to skip over "Enum" and backslash */
+ search_dyn_data(dd_path, &lm_path[5], (buffer[3] - '1'));
+ }
+ }
+
+ index = 0;
+
+ do
+ {
+ size = 1023;
+
+ result = RegEnumKeyEx(
+ key,
+ index++,
+ buffer,
+ &size,
+ NULL,
+ NULL,
+ NULL,
+ &last_write);
+
+ if (result == ERROR_SUCCESS)
+ {
+ lm_path[length] = '\\';
+ lm_path[length + 1] = '\0';
+ strcpy(&lm_path[length + 1], buffer);
+
+ search_local_machine(lm_path, dd_path);
+
+ lm_path[length] = '\0';
+ }
+ }
+ while (result == ERROR_SUCCESS);
+
+ RegCloseKey(key);
+ }
+}
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+*
+* GET_LPT_ADDRESSES_FROM_REGISTRY
+*
+* Searches Win95/98 registry recursively to get I/O port addresses for
+* parallel ports.
+*/
+void get_lpt_addresses_from_registry()
+{
+ char lm_path[1024];
+ char dd_path[1024];
+
+ strcpy(lm_path, "Enum");
+ strcpy(dd_path, "Config Manager");
+ search_local_machine(lm_path, dd_path);
+}
+#endif
+#endif
+
+void initialize_jtag_hardware()
+{
+ if (specified_com_port)
+ {
+ com_port = open(serial_port_name, O_RDWR);
+ if (com_port == -1)
+ {
+ fprintf(stderr, "Error: can't open serial port \"%s\"\n",
+ serial_port_name);
+ }
+ else
+ {
+ int i = 0, result = 0;
+ char data = 0;
+
+ data = 0x7e;
+ write(com_port, &data, 1);
+
+ for (i = 0; (i < 100) && (result != 1); ++i)
+ {
+ result = read(com_port, &data, 1);
+ }
+
+ if (result == 1)
+ {
+ data = 0x70; write(com_port, &data, 1); /* TDO echo off */
+ data = 0x72; write(com_port, &data, 1); /* auto LEDs off */
+ data = 0x74; write(com_port, &data, 1); /* ERROR LED off */
+ data = 0x76; write(com_port, &data, 1); /* DONE LED off */
+ data = 0x60; write(com_port, &data, 1); /* signals low */
+ }
+ else
+ {
+ fprintf(stderr, "Error: BitBlaster is not responding on %s\n",
+ serial_port_name);
+ close(com_port);
+ com_port = -1;
+ }
+ }
+ }
+ else
+ {
+#if PORT == WINDOWS || PORT == DOS
+
+#if PORT == WINDOWS
+ if (windows_nt)
+ {
+ initialize_nt_driver();
+ }
+ else
+ {
+#ifdef __BORLANDC__
+ fprintf(stderr, "Error: parallel port access is not available\n");
+#else
+ if (!specified_lpt_addr)
+ {
+ get_lpt_addresses_from_registry();
+
+ lpt_addr = 0;
+
+ if (specified_lpt_port)
+ {
+ lpt_addr = lpt_addresses_from_registry[lpt_port - 1];
+ }
+
+ if (lpt_addr == 0)
+ {
+ if (lpt_addresses_from_registry[3] != 0)
+ lpt_addr = lpt_addresses_from_registry[3];
+ if (lpt_addresses_from_registry[2] != 0)
+ lpt_addr = lpt_addresses_from_registry[2];
+ if (lpt_addresses_from_registry[1] != 0)
+ lpt_addr = lpt_addresses_from_registry[1];
+ if (lpt_addresses_from_registry[0] != 0)
+ lpt_addr = lpt_addresses_from_registry[0];
+ }
+
+ if (lpt_addr == 0)
+ {
+ if (specified_lpt_port)
+ {
+ lpt_addr = lpt_addr_table[lpt_port - 1];
+ }
+ else
+ {
+ lpt_addr = lpt_addr_table[0];
+ }
+ }
+ }
+ initial_lpt_ctrl = windows_nt ? 0x0c : read_byteblaster(2);
+#endif
+ }
+#endif
+
+#if PORT == DOS
+ /*
+ * Read word at specific memory address to get the LPT port address
+ */
+ WORD *bios_address = (WORD *) 0x00400008;
+
+ if (!specified_lpt_addr)
+ {
+ lpt_addr = bios_address[lpt_port - 1];
+
+ if ((lpt_addr != 0x278) &&
+ (lpt_addr != 0x27c) &&
+ (lpt_addr != 0x378) &&
+ (lpt_addr != 0x37c) &&
+ (lpt_addr != 0x3b8) &&
+ (lpt_addr != 0x3bc))
+ {
+ lpt_addr = lpt_addr_table[lpt_port - 1];
+ }
+ }
+ initial_lpt_ctrl = read_byteblaster(2);
+#endif
+
+ /* set AUTO-FEED low to enable ByteBlaster (value to port inverted) */
+ /* set DIRECTION low for data output from parallel port */
+ write_byteblaster(2, (initial_lpt_ctrl | 0x02) & 0xDF);
+#endif
+ }
+}
+
+void close_jtag_hardware()
+{
+ if (specified_com_port)
+ {
+ if (com_port != -1) close(com_port);
+ }
+ else
+ {
+#if PORT == WINDOWS || PORT == DOS
+ /* set AUTO-FEED high to disable ByteBlaster */
+ write_byteblaster(2, initial_lpt_ctrl & 0xfd);
+
+#if PORT == WINDOWS
+ if (windows_nt && (nt_device_handle != INVALID_HANDLE_VALUE))
+ {
+ if (port_io_count > 0) flush_ports();
+
+ CloseHandle(nt_device_handle);
+ }
+#endif
+#endif
+ }
+}
+
+#if PORT == WINDOWS
+/**************************************************************************/
+/* */
+
+BOOL initialize_nt_driver()
+
+/* */
+/* Uses CreateFile() to open a connection to the Windows NT device */
+/* driver. */
+/* */
+/**************************************************************************/
+{
+ BOOL status = FALSE;
+
+ ULONG buffer[1];
+ ULONG returned_length = 0;
+ char nt_lpt_str[] = { '\\', '\\', '.', '\\',
+ 'A', 'L', 'T', 'L', 'P', 'T', '1', '\0' };
+
+ nt_lpt_str[10] = (char) ('1' + (lpt_port - 1));
+
+ nt_device_handle = CreateFile(
+ nt_lpt_str,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+
+ if (nt_device_handle == INVALID_HANDLE_VALUE)
+ {
+ fprintf(stderr,
+ "I/O error: cannot open device %s\nCheck port number and device driver installation",
+ nt_lpt_str);
+ }
+ else
+ {
+ if (DeviceIoControl(
+ nt_device_handle, /* Handle to device */
+ PGDC_IOCTL_GET_DEVICE_INFO_PP, /* IO Control code */
+ (ULONG *)NULL, /* Buffer to driver. */
+ 0, /* Length of buffer in bytes. */
+ &buffer, /* Buffer from driver. */
+ sizeof(ULONG), /* Length of buffer in bytes. */
+ &returned_length, /* Bytes placed in data_buffer. */
+ NULL)) /* Wait for operation to complete */
+ {
+ if (returned_length == sizeof(ULONG))
+ {
+ if (buffer[0] == PGDC_HDLC_NTDRIVER_VERSION)
+ {
+ status = TRUE;
+ }
+ else
+ {
+ fprintf(stderr,
+ "I/O error: device driver %s is not compatible\n(Driver version is %lu, expected version %lu.\n",
+ nt_lpt_str,
+ (unsigned long) buffer[0],
+ (unsigned long) PGDC_HDLC_NTDRIVER_VERSION);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "I/O error: device driver %s is not compatible.\n",
+ nt_lpt_str);
+ }
+ }
+
+ if (!status)
+ {
+ CloseHandle(nt_device_handle);
+ nt_device_handle = INVALID_HANDLE_VALUE;
+ }
+ }
+
+ if (!status)
+ {
+ /* error message already given */
+ exit(1);
+ }
+
+ return (status);
+}
+#endif
+
+#if PORT == WINDOWS || PORT == DOS
+/**************************************************************************/
+/* */
+
+void write_byteblaster
+(
+ int port,
+ int data
+)
+
+/* */
+/**************************************************************************/
+{
+#if PORT == WINDOWS
+ BOOL status = FALSE;
+
+ int returned_length = 0;
+ int buffer[2];
+
+ if (windows_nt)
+ {
+ /*
+ * On Windows NT, access hardware through device driver
+ */
+ if (port == 0)
+ {
+ port_io_buffer[port_io_count].data = (USHORT) data;
+ port_io_buffer[port_io_count].command = PGDC_WRITE_PORT;
+ ++port_io_count;
+
+ if (port_io_count >= PORT_IO_BUFFER_SIZE) flush_ports();
+ }
+ else
+ {
+ if (port_io_count > 0) flush_ports();
+
+ buffer[0] = port;
+ buffer[1] = data;
+
+ status = DeviceIoControl(
+ nt_device_handle, /* Handle to device */
+ PGDC_IOCTL_WRITE_PORT_PP, /* IO Control code for write */
+ (ULONG *)&buffer, /* Buffer to driver. */
+ 2 * sizeof(int), /* Length of buffer in bytes. */
+ (ULONG *)NULL, /* Buffer from driver. Not used. */
+ 0, /* Length of buffer in bytes. */
+ (ULONG *)&returned_length, /* Bytes returned. Should be zero. */
+ NULL); /* Wait for operation to complete */
+
+ if ((!status) || (returned_length != 0))
+ {
+ fprintf(stderr, "I/O error: Cannot access ByteBlaster hardware\n");
+ CloseHandle(nt_device_handle);
+ exit(1);
+ }
+ }
+ }
+ else
+#endif
+ {
+ /*
+ * On Windows 95, access hardware directly
+ */
+ outp((WORD)(port + lpt_addr), (WORD)data);
+ }
+}
+
+/**************************************************************************/
+/* */
+
+int read_byteblaster
+(
+ int port
+)
+
+/* */
+/**************************************************************************/
+{
+ int data = 0;
+
+#if PORT == WINDOWS
+
+ BOOL status = FALSE;
+
+ int returned_length = 0;
+
+ if (windows_nt)
+ {
+ /* flush output cache buffer before reading from device */
+ if (port_io_count > 0) flush_ports();
+
+ /*
+ * On Windows NT, access hardware through device driver
+ */
+ status = DeviceIoControl(
+ nt_device_handle, /* Handle to device */
+ PGDC_IOCTL_READ_PORT_PP, /* IO Control code for Read */
+ (ULONG *)&port, /* Buffer to driver. */
+ sizeof(int), /* Length of buffer in bytes. */
+ (ULONG *)&data, /* Buffer from driver. */
+ sizeof(int), /* Length of buffer in bytes. */
+ (ULONG *)&returned_length, /* Bytes placed in data_buffer. */
+ NULL); /* Wait for operation to complete */
+
+ if ((!status) || (returned_length != sizeof(int)))
+ {
+ fprintf(stderr, "I/O error: Cannot access ByteBlaster hardware\n");
+ CloseHandle(nt_device_handle);
+ exit(1);
+ }
+ }
+ else
+#endif
+ {
+ /*
+ * On Windows 95, access hardware directly
+ */
+ data = inp((WORD)(port + lpt_addr));
+ }
+
+ return (data & 0xff);
+}
+
+#if PORT == WINDOWS
+void flush_ports(void)
+{
+ ULONG n_writes = 0L;
+ BOOL status;
+
+ status = DeviceIoControl(
+ nt_device_handle, /* handle to device */
+ PGDC_IOCTL_PROCESS_LIST_PP, /* IO control code */
+ (LPVOID)port_io_buffer, /* IN buffer (list buffer) */
+ port_io_count * sizeof(struct PORT_IO_LIST_STRUCT),/* length of IN buffer in bytes */
+ (LPVOID)port_io_buffer, /* OUT buffer (list buffer) */
+ port_io_count * sizeof(struct PORT_IO_LIST_STRUCT),/* length of OUT buffer in bytes */
+ &n_writes, /* number of writes performed */
+ 0); /* wait for operation to complete */
+
+ if ((!status) || ((port_io_count * sizeof(struct PORT_IO_LIST_STRUCT)) != n_writes))
+ {
+ fprintf(stderr, "I/O error: Cannot access ByteBlaster hardware\n");
+ CloseHandle(nt_device_handle);
+ exit(1);
+ }
+
+ port_io_count = 0;
+}
+#endif /* PORT == WINDOWS */
+#endif /* PORT == WINDOWS || PORT == DOS */
+
+#if 0
+#if !defined (DEBUG)
+#pragma optimize ("ceglt", off)
+#endif
+#endif
+
+void delay_loop(long count)
+{
+ while (count != 0L) count--;
+}
+
+#if PORT == EMBEDDED
+
+static void jbi_init_mm(void)
+{
+#if defined(USE_STATIC_MEMORY)
+ int i;
+#endif /* USE_STATIC_MEMORY */
+
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ n_bytes_allocated = 0;
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+#if defined(MEM_TRACKER)
+ peak_memory_usage = 0;
+ peak_allocations = 0;
+ n_allocations = 0;
+#if defined(USE_STATIC_MEMORY)
+ n_bytes_not_recovered = 0;
+#endif /* USE_STATIC_MEMORY */
+#endif /* MEM_TRACKER */
+
+#if defined(USE_STATIC_MEMORY)
+ jbi_dbg(DEBUG_DETAIL, "static_memory_heap: 0x%p(0x%x)\n",
+ static_memory_heap, N_STATIC_MEMORY_BYTES);
+ for (i = 0; i < N_STATIC_MEMORY_BYTES; i++) {
+ static_memory_heap[i] = 0;
+ }
+#endif /* USE_STATIC_MEMORY */
+
+ jbi_delay_us = 0;
+ jbi_delay_count = 0;
+ jbi_peak_us = 0;
+}
+
+static void jbi_exit_mm(void)
+{
+#if defined(USE_STATIC_MEMORY) || defined(MEM_TRACKER)
+ jbi_dbg(DEBUG_DETAIL, "n_bytes_allocated: %u\n", n_bytes_allocated);
+ n_bytes_allocated = 0;
+#endif /* USE_STATIC_MEMORY || MEM_TRACKER */
+
+#if defined(MEM_TRACKER)
+ jbi_dbg(DEBUG_DETAIL, "peak_memory_usage: %u\n", peak_memory_usage);
+ jbi_dbg(DEBUG_DETAIL, "peak_allocations: %u\n", peak_allocations);
+ jbi_dbg(DEBUG_DETAIL, "n_allocations: %u\n", n_allocations);
+ peak_memory_usage = 0;
+ peak_allocations = 0;
+ n_allocations = 0;
+#if defined(USE_STATIC_MEMORY)
+ jbi_dbg(DEBUG_DETAIL, "n_bytes_not_recovered: %u\n", n_bytes_not_recovered);
+ n_bytes_not_recovered = 0;
+#endif /* USE_STATIC_MEMORY */
+#endif /* MEM_TRACKER */
+
+ jbi_dbg(DEBUG_DETAIL, "jbi_delay: %ld us, %ld count, peak %ld us\n",
+ jbi_delay_us, jbi_delay_count, jbi_peak_us);
+}
+
+static char *get_exit_string(int format_version, int exit_code)
+{
+ char *exit_string = NULL;
+
+ if (format_version == 2){
+ switch (exit_code) {
+ case 0:
+ exit_string = "Success";
+ break;
+ case 1:
+ exit_string = "Checking chain failure";
+ break;
+ case 2:
+ exit_string = "Reading IDCODE failure";
+ break;
+ case 3:
+ exit_string = "Reading USERCODE failure";
+ break;
+ case 4:
+ exit_string = "Reading UESCODE failure";
+ break;
+ case 5:
+ exit_string = "Entering ISP failure";
+ break;
+ case 6:
+ exit_string = "Unrecognized device";
+ break;
+ case 7:
+ exit_string = "Device revision is not supported";
+ break;
+ case 8:
+ exit_string = "Erase failure";
+ break;
+ case 9:
+ exit_string = "Device is not blank";
+ break;
+ case 10:
+ exit_string = "Device programming failure";
+ break;
+ case 11:
+ exit_string = "Device verify failure";
+ break;
+ case 12:
+ exit_string = "Read failure"; break;
+ case 13:
+ exit_string = "Calculating checksum failure";
+ break;
+ case 14:
+ exit_string = "Setting security bit failure";
+ break;
+ case 15:
+ exit_string = "Querying security bit failure";
+ break;
+ case 16:
+ exit_string = "Exiting ISP failure";
+ break;
+ case 17:
+ exit_string = "Performing system test failure";
+ break;
+ default:
+ exit_string = "Unknown exit code";
+ break;
+ }
+ } else {
+ switch (exit_code) {
+ case 0:
+ exit_string = "Success";
+ break;
+ case 1:
+ exit_string = "Illegal initialization values";
+ break;
+ case 2:
+ exit_string = "Unrecognized device";
+ break;
+ case 3:
+ exit_string = "Device revision is not supported";
+ break;
+ case 4:
+ exit_string = "Device programming failure";
+ break;
+ case 5:
+ exit_string = "Device is not blank";
+ break;
+ case 6:
+ exit_string = "Device verify failure";
+ break;
+ case 7:
+ exit_string = "SRAM configuration failure";
+ break;
+ default:
+ exit_string = "Unknown exit code";
+ break;
+ }
+ }
+
+ return exit_string;
+}
+
+static void jbi_help(void)
+{
+ fprintf(stderr, "Usage: jbi [options]\n");
+ fprintf(stderr, "\nAvailable options:\n");
+ fprintf(stderr, " -h : show help message\n");
+ fprintf(stderr, " -v : show verbose messages\n");
+ fprintf(stderr, " -i : show file info only - does not execute any action\n");
+ fprintf(stderr, " -a : specify an action name (Jam STAPL)\n");
+ fprintf(stderr, " -d : initialize variable to specified value (Jam 1.1)\n");
+ fprintf(stderr, " -d : enable optional procedure (Jam STAPL)\n");
+ fprintf(stderr, " -d : disable recommended procedure (Jam STAPL)\n");
+ fprintf(stderr, " -r : don't reset JTAG TAP after use\n");
+}
+
+int jbi_debug(int level)
+{
+ jbi_debug_level = level;
+
+ return 0;
+}
+
+int jbi_main(unsigned char *addr, unsigned long size, int argc, char * const argv[])
+{
+ BOOL help = FALSE;
+ BOOL error = FALSE;
+ long offset = 0L;
+ long error_address = 0L;
+ JBI_RETURN_TYPE crc_result = JBIC_SUCCESS;
+ JBI_RETURN_TYPE exec_result = JBIC_SUCCESS;
+ unsigned short expected_crc = 0;
+ unsigned short actual_crc = 0;
+ char key[33] = {0};
+ char value[257] = {0};
+ int exit_status = 0;
+ int arg = 0;
+ int exit_code = 0;
+ int format_version = 0;
+ char *workspace = NULL;
+ char *action = NULL;
+ char *init_list[10];
+ int init_count = 0;
+ long workspace_size = 0;
+ char *exit_string = NULL;
+ int reset_jtag = 1;
+ int execute_program = 1;
+ int action_count = 0;
+ int procedure_count = 0;
+ int index = 0;
+ char *action_name = NULL;
+ char *description = NULL;
+ JBI_PROCINFO *procedure_list = NULL;
+ JBI_PROCINFO *procptr = NULL;
+ char *endp = NULL;
+
+ verbose = FALSE;
+
+ init_list[0] = NULL;
+
+ /* print out the version string and copyright message */
+ printf("Jam STAPL ByteCode Player Version 2.2\n");
+ printf("Copyright (C) 1998-2001 Altera Corporation\n\n");
+
+ for (arg = 0; arg < argc; arg++) {
+ if (argv[arg][0] == '-') {
+ switch (toupper(argv[arg][1])) {
+ case 'A': /* set action name */
+ if (action == NULL) {
+ action = &argv[arg][2];
+ } else {
+ error = TRUE;
+ }
+ break;
+ case 'D': /* initialization list */
+ if (argv[arg][2] == '"') {
+ init_list[init_count] = &argv[arg][3];
+ } else {
+ init_list[init_count] = &argv[arg][2];
+ }
+ init_list[++init_count] = NULL;
+ break;
+ case 'R': /* don't reset the JTAG chain after use */
+ reset_jtag = 0;
+ break;
+ case 'M': /* set memory size */
+ workspace = (char *) simple_strtoul(&argv[arg][2], &endp, 16);
+ if (workspace == NULL) {
+ printf("Error workspace\n");
+ error = TRUE;
+ } else {
+ if (*endp == '.') {
+ workspace_size = simple_strtoul(endp + 1, &endp, 16);
+ if (*endp != '\0') {
+ printf("Error workspace size end\n");
+ error = TRUE;
+ }
+ } else {
+ printf("No workspace size\n");
+ error = TRUE;
+ }
+ }
+ break;
+ case 'H': /* help */
+ help = TRUE;
+ break;
+ case 'V': /* verbose */
+ verbose = TRUE;
+ break;
+ case 'I': /* show info only, do not execute */
+ verbose = TRUE;
+ execute_program = 0;
+ break;
+ default:
+ error = TRUE;
+ break;
+ }
+ } else {
+ error = TRUE;
+ }
+
+ if (error) {
+ fprintf(stderr, "Illegal argument: \"%s\"\n", argv[arg]);
+ help = TRUE;
+ error = FALSE;
+ }
+ }
+
+ if (help) {
+ jbi_help();
+ return 0;
+ }
+
+ /* Calibrate the delay loop function */
+ calibrate_delay();
+
+ jbi_init_mm();
+
+ /* Check CRC */
+ crc_result = jbi_check_crc(addr, size, &expected_crc, &actual_crc);
+ if (verbose || (crc_result == JBIC_CRC_ERROR)) {
+ switch (crc_result) {
+ case JBIC_SUCCESS:
+ printf("CRC matched: CRC value = %04X\n", actual_crc);
+ break;
+ case JBIC_CRC_ERROR:
+ printf("CRC mismatch: expected %04X, actual %04X\n", expected_crc, actual_crc);
+ return -1;
+ case JBIC_UNEXPECTED_END:
+ printf("Expected CRC not found, actual CRC value = %04X\n", actual_crc);
+ return -1;
+ case JBIC_IO_ERROR:
+ printf("Error: File format is not recognized.\n");
+ return -1;
+ default:
+ printf("CRC function returned error code %d\n", crc_result);
+ return -1;
+ }
+ }
+
+ if (verbose) {
+ /* Display file format version */
+ jbi_get_file_info(addr, size, &format_version,
+ &action_count, &procedure_count);
+
+ printf("File format is %s ByteCode format\n",
+ (format_version == 2) ? "Jam STAPL" : "pre-standardized Jam 1.1");
+
+ /* Dump out NOTE fields */
+ while (jbi_get_note(addr, size, &offset, key, value, 256) == 0) {
+ printf("NOTE \"%s\" = \"%s\"\n", key, value);
+ }
+
+ /* Dump the action table */
+ if ((format_version == 2) && (action_count > 0)) {
+ printf("\nActions available in this file:\n");
+
+ for (index = 0; index < action_count; ++index) {
+ jbi_get_action_info(addr, size,
+ index, &action_name, &description, &procedure_list);
+
+ if (description == NULL) {
+ printf("%s\n", action_name);
+ } else {
+ printf("%s \"%s\"\n", action_name, description);
+ }
+
+ procptr = procedure_list;
+ while (procptr != NULL) {
+ if (procptr->attributes != 0) {
+ printf(" %s (%s)\n", procptr->name,
+ (procptr->attributes == 1) ? "optional" : "recommended");
+ }
+
+ procedure_list = procptr->next;
+ jbi_free(procptr);
+ procptr = procedure_list;
+ }
+ }
+
+ /* add a blank line before execution messages */
+ if (execute_program)
+ printf("\n");
+ }
+ }
+
+ if (execute_program) {
+ /* Execute the Jam STAPL ByteCode program */
+ exec_result = jbi_execute(addr, size, workspace,
+ workspace_size, action, init_list, reset_jtag,
+ &error_address, &exit_code, &format_version);
+ if (exec_result == JBIC_SUCCESS) {
+ exit_string = get_exit_string(format_version, exit_code);
+ printf("Exit code = %d... %s\n", exit_code, exit_string);
+ } else if ((format_version == 2) && (exec_result == JBIC_ACTION_NOT_FOUND)) {
+ if ((action == NULL) || (*action == '\0')) {
+ printf("Error: no action specified for Jam STAPL file.\n"
+ "Program terminated.\n");
+ } else {
+ printf("Error: action \"%s\" is not supported for this Jam STAPL file.\n"
+ "Program terminated.\n", action);
+ }
+ } else if (exec_result < MAX_ERROR_CODE) {
+ printf("Error at address %ld: %s.\nProgram terminated.\n",
+ error_address, error_text[exec_result]);
+ } else {
+ printf("Unknown error code %d\n", exec_result);
+ }
+ }
+
+ if (jtag_hardware_initialized) {
+ close_jtag_hardware();
+ jtag_hardware_initialized = FALSE;
+ }
+
+#if defined(MEM_TRACKER)
+ if (verbose) {
+#if defined(USE_STATIC_MEMORY)
+ fprintf(stdout, "Memory Usage Info: static memory size = %uBytes (%dKB)\n",
+ N_STATIC_MEMORY_BYTES, N_STATIC_MEMORY_KBYTES);
+#endif /* USE_STATIC_MEMORY */
+ fprintf(stdout, "Memory Usage Info: peak memory usage = %uBytes (%dKB)\n",
+ peak_memory_usage, (peak_memory_usage + 1023) / 1024);
+ fprintf(stdout, "Memory Usage Info: peak allocations = %u\n",
+ peak_allocations);
+#if defined(USE_STATIC_MEMORY)
+ if ((n_bytes_allocated - n_bytes_not_recovered) != 0) {
+ fprintf(stdout, "Memory Usage Info: bytes still allocated = %d (%dKB)\n",
+ (n_bytes_allocated - n_bytes_not_recovered),
+ ((n_bytes_allocated - n_bytes_not_recovered) + 1023) / 1024);
+ }
+#else /* USE_STATIC_MEMORY */
+ if (n_bytes_allocated != 0) {
+ fprintf(stdout, "Memory Usage Info: bytes still allocated = %d (%dKB)\n",
+ n_bytes_allocated, (n_bytes_allocated + 1023) / 1024);
+ }
+#endif /* USE_STATIC_MEMORY */
+ if (n_allocations != 0) {
+ fprintf(stdout, "Memory Usage Info: allocations not freed = %d\n", n_allocations);
+ }
+ }
+#endif /* MEM_TRACKER */
+
+ jbi_exit_mm();
+
+ if (exec_result != JBIC_SUCCESS) {
+ return (-exec_result);
+ }
+
+ if (exit_code != 0) {
+ return (exit_code);
+ }
+
+ return (exit_status);
+}
+
+#endif /* PORT == EMBEDDED */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.h
new file mode 100644
index 0000000000..5e5c5332f3
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_cpld/jbistub.h
@@ -0,0 +1,95 @@
+#ifndef __JBISTUB_H__
+#define __JBISTUB_H__
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/Makefile
new file mode 100644
index 0000000000..caad449480
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_ispvme.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_ispvme.c
new file mode 100644
index 0000000000..9841782290
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_ispvme.c
@@ -0,0 +1,450 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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);
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c
new file mode 100644
index 0000000000..b8896ed75f
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_cpld_upgrade_ispvme.c
@@ -0,0 +1,691 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/* 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 = ¤t_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 = ¤t_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();
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_ispvme.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_ispvme.c
new file mode 100644
index 0000000000..e8f75844ae
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/firmware_ispvme.c
@@ -0,0 +1,140 @@
+#include
+#include
+#include
+
+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");
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_cpld_ispvme.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_cpld_ispvme.h
new file mode 100644
index 0000000000..eb737d3a56
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_cpld_ispvme.h
@@ -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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_ispvme.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_ispvme.h
new file mode 100644
index 0000000000..39baf3f307
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_ispvme/include/firmware_ispvme.h
@@ -0,0 +1,86 @@
+#ifndef __FIRMWARE_H__
+#define __FIRMWARE_H__
+
+#include
+#include
+
+#include
+
+/* 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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/Makefile
new file mode 100644
index 0000000000..a1d6d2e2ef
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware.c
new file mode 100644
index 0000000000..fec51d6238
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware.c
@@ -0,0 +1,143 @@
+#include
+#include
+#include
+
+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");
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs.c
new file mode 100644
index 0000000000..a823cdc4f2
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs.c
@@ -0,0 +1,495 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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);
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs_upgrade.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs_upgrade.c
new file mode 100644
index 0000000000..8b883006de
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/firmware_sysfs_upgrade.c
@@ -0,0 +1,258 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs.h
new file mode 100644
index 0000000000..9da2303c7c
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs.h
@@ -0,0 +1,88 @@
+#ifndef __FIRMWARE_SYSFS_H__
+#define __FIRMWARE_SYSFS_H__
+
+#include
+#include
+
+#include
+
+/* 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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs_upgrade.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs_upgrade.h
new file mode 100644
index 0000000000..9c6b970274
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/firmware_driver_sysfs/include/firmware_sysfs_upgrade.h
@@ -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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/include/firmware_upgrade.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/include/firmware_upgrade.h
new file mode 100644
index 0000000000..600c69646b
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_driver/include/firmware_upgrade.h
@@ -0,0 +1,57 @@
+#ifndef __FIRMWARE_UPGRADE_H__
+#define __FIRMWARE_UPGRADE_H__
+
+#include
+
+#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
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/Makefile b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/Makefile
new file mode 100644
index 0000000000..176d44d2ab
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/Makefile
@@ -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)
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/crc32.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/crc32.c
new file mode 100644
index 0000000000..5b60b40ad1
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/crc32.c
@@ -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 */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/debug.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/debug.c
new file mode 100644
index 0000000000..dc1b1ccfc7
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/debug.c
@@ -0,0 +1,60 @@
+/*
+ * debug.c
+ * firmware upgrade debug switch control
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/firmware_app.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/firmware_app.c
new file mode 100644
index 0000000000..ecdc37ef35
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/firmware_app.c
@@ -0,0 +1,985 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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;
+ }
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/hardware.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/hardware.c
new file mode 100644
index 0000000000..c43c9095fd
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/hardware.c
@@ -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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/********************************************************************************
+* 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);
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ispvm_ui.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ispvm_ui.c
new file mode 100644
index 0000000000..69a8e53852
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ispvm_ui.c
@@ -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
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/***************************************************************
+*
+* 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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ivm_core.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ivm_core.c
new file mode 100644
index 0000000000..540be481d3
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_gpio_vme/ivm_core.c
@@ -0,0 +1,3097 @@
+/***************************************************************
+*
+* Lattice Semiconductor Corp. Copyright 2009
+*
+* 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.
+*
+* Revision History of ivm_core.c module:
+* 4/25/06 ht Change some variables from unsigned short or int
+* to long int to make the code compiler independent.
+* 5/24/06 ht Support using RESET (TRST) pin as a special purpose
+* control pin such as triggering the loading of known
+* state exit.
+* 3/6/07 ht added functions to support output to terminals
+*
+* 09/24/07 NN Type cast mismatch variables
+* Moved the sclock() function to hardware.c
+* 08/28/08 NN Added Calculate checksum support.
+* 4/1/09 Nguyen replaced the recursive function call codes on
+* the ispVMLCOUNT function
+*
+***************************************************************/
+
+#include
+#include
+#include
+#include
+
+/***************************************************************
+*
+* Global variables used to specify the flow control and data type.
+*
+* g_usFlowControl: flow control register. Each bit in the
+* register can potentially change the
+* personality of the embedded engine.
+* g_usDataType: holds the data type of the current row.
+*
+***************************************************************/
+
+unsigned short g_usFlowControl = 0x0000;
+unsigned short g_usDataType = 0x0000;
+
+/***************************************************************
+*
+* Global variables used to specify the ENDDR and ENDIR.
+*
+* g_ucEndDR: the state that the device goes to after SDR.
+* g_ucEndIR: the state that the device goes to after SIR.
+*
+***************************************************************/
+
+unsigned char g_ucEndDR = DRPAUSE;
+unsigned char g_ucEndIR = IRPAUSE;
+
+/***************************************************************
+*
+* Global variables used to support header/trailer.
+*
+* g_usHeadDR: the number of lead devices in bypass.
+* g_usHeadIR: the sum of IR length of lead devices.
+* g_usTailDR: the number of tail devices in bypass.
+* g_usTailIR: the sum of IR length of tail devices.
+*
+***************************************************************/
+
+unsigned short g_usHeadDR = 0;
+unsigned short g_usHeadIR = 0;
+unsigned short g_usTailDR = 0;
+unsigned short g_usTailIR = 0;
+
+/***************************************************************
+*
+* Global variable to store the number of bits of data or instruction
+* to be shifted into or out from the device.
+*
+***************************************************************/
+
+unsigned short g_usiDataSize = 0;
+
+/***************************************************************
+*
+* Stores the frequency. Default to 1 MHz.
+*
+***************************************************************/
+
+int g_iFrequency = 1000;
+
+/***************************************************************
+*
+* Stores the maximum amount of ram needed to hold a row of data.
+*
+***************************************************************/
+
+unsigned short g_usMaxSize = 0;
+
+/***************************************************************
+*
+* Stores the LSH or RSH value.
+*
+***************************************************************/
+
+unsigned short g_usShiftValue = 0;
+
+/***************************************************************
+*
+* Stores the current repeat loop value.
+*
+***************************************************************/
+
+unsigned short g_usRepeatLoops = 0;
+
+/***************************************************************
+*
+* Stores the current vendor.
+*
+***************************************************************/
+
+signed char g_cVendor = LATTICE;
+
+/***************************************************************
+*
+* Stores the VME file CRC.
+*
+***************************************************************/
+
+unsigned short g_usCalculatedCRC = 0;
+
+/***************************************************************
+*
+* Stores the Device Checksum.
+*
+***************************************************************/
+//08/28/08 NN Added Calculate checksum support.
+unsigned long g_usChecksum = 0;
+unsigned int g_uiChecksumIndex = 0;
+
+/***************************************************************
+*
+* Stores the current state of the JTAG state machine.
+*
+***************************************************************/
+
+signed char g_cCurrentJTAGState = 0;
+
+/***************************************************************
+*
+* Global variables used to support looping.
+*
+* g_pucHeapMemory: holds the entire repeat loop.
+* g_iHeapCounter: points to the current byte in the repeat loop.
+* g_iHEAPSize: the current size of the repeat in bytes.
+*
+***************************************************************/
+
+unsigned char *g_pucHeapMemory = NULL;
+unsigned short g_iHeapCounter = 0;
+unsigned short g_iHEAPSize = 0;
+
+/***************************************************************
+*
+* Global variables used to support intelligent programming.
+*
+* g_usIntelDataIndex: points to the current byte of the
+* intelligent buffer.
+* g_usIntelBufferSize: holds the size of the intelligent
+* buffer.
+*
+***************************************************************/
+
+unsigned short g_usIntelDataIndex = 0;
+unsigned short g_usIntelBufferSize = 0;
+
+/****************************************************************************
+*
+* Holds the maximum size of each respective buffer. These variables are used
+* to write the HEX files when converting VME to HEX.
+*
+*****************************************************************************/
+
+unsigned short g_usTDOSize = 0;
+unsigned short g_usMASKSize = 0;
+unsigned short g_usTDISize = 0;
+unsigned short g_usDMASKSize = 0;
+unsigned short g_usLCOUNTSize = 0;
+unsigned short g_usHDRSize = 0;
+unsigned short g_usTDRSize = 0;
+unsigned short g_usHIRSize = 0;
+unsigned short g_usTIRSize = 0;
+unsigned short g_usHeapSize = 0;
+
+/***************************************************************
+*
+* Global variables used to store data.
+*
+* g_pucOutMaskData: local RAM to hold one row of MASK data.
+* g_pucInData: local RAM to hold one row of TDI data.
+* g_pucOutData: local RAM to hold one row of TDO data.
+* g_pucHIRData: local RAM to hold the current SIR header.
+* g_pucTIRData: local RAM to hold the current SIR trailer.
+* g_pucHDRData: local RAM to hold the current SDR header.
+* g_pucTDRData: local RAM to hold the current SDR trailer.
+* g_pucIntelBuffer: local RAM to hold the current intelligent buffer.
+* g_pucOutDMaskData: local RAM to hold one row of DMASK data.
+*
+***************************************************************/
+
+unsigned char *g_pucOutMaskData = NULL,
+*g_pucInData = NULL,
+*g_pucOutData = NULL,
+*g_pucHIRData = NULL,
+*g_pucTIRData = NULL,
+*g_pucHDRData = NULL,
+*g_pucTDRData = NULL,
+*g_pucIntelBuffer = NULL,
+*g_pucOutDMaskData = NULL;
+
+/***************************************************************
+*
+* JTAG state machine transition table.
+*
+***************************************************************/
+
+struct {
+ unsigned char CurState; /* From this state */
+ unsigned char NextState; /* Step to this state */
+ unsigned char Pattern; /* The tragetory of TMS */
+ unsigned char Pulses; /* The number of steps */
+} g_JTAGTransistions[25] = {
+ { RESET, RESET, 0xFC, 6 }, /* Transitions from RESET */
+ { RESET, IDLE, 0x00, 1 },
+ { RESET, DRPAUSE, 0x50, 5 },
+ { RESET, IRPAUSE, 0x68, 6 },
+ { IDLE, RESET, 0xE0, 3 }, /* Transitions from IDLE */
+ { IDLE, DRPAUSE, 0xA0, 4 },
+ { IDLE, IRPAUSE, 0xD0, 5 },
+ { DRPAUSE, RESET, 0xF8, 5 }, /* Transitions from DRPAUSE */
+ { DRPAUSE, IDLE, 0xC0, 3 },
+ { DRPAUSE, IRPAUSE, 0xF4, 7 },
+ { DRPAUSE, DRPAUSE, 0xE8, 6 }, /* 06/14/06 Support POLING STATUS LOOP*/
+ { IRPAUSE, RESET, 0xF8, 5 }, /* Transitions from IRPAUSE */
+ { IRPAUSE, IDLE, 0xC0, 3 },
+ { IRPAUSE, DRPAUSE, 0xE8, 6 },
+ { DRPAUSE, SHIFTDR, 0x80, 2 }, /* Extra transitions using SHIFTDR */
+ { IRPAUSE, SHIFTDR, 0xE0, 5 },
+ { SHIFTDR, DRPAUSE, 0x80, 2 },
+ { SHIFTDR, IDLE, 0xC0, 3 },
+ { IRPAUSE, SHIFTIR, 0x80, 2 }, /* Extra transitions using SHIFTIR */
+ { SHIFTIR, IRPAUSE, 0x80, 2 },
+ { SHIFTIR, IDLE, 0xC0, 3 },
+ { DRPAUSE, DRCAPTURE, 0xE0, 4 }, /* 11/15/05 Support DRCAPTURE*/
+ { DRCAPTURE, DRPAUSE, 0x80, 2 },
+ { IDLE, DRCAPTURE, 0x80, 2 },
+ { IRPAUSE, DRCAPTURE, 0xE0, 4 }
+};
+
+/***************************************************************
+*
+* List to hold all LVDS pairs.
+*
+***************************************************************/
+
+LVDSPair *g_pLVDSList = NULL;
+unsigned short g_usLVDSPairCount = 0;
+
+/***************************************************************
+*
+* Function prototypes.
+*
+***************************************************************/
+
+signed char ispVMCode();
+signed char ispVMDataCode();
+long int ispVMDataSize();
+void ispVMData(unsigned char *Data);
+signed char ispVMShift(signed char Code);
+signed char ispVMAmble(signed char Code);
+signed char ispVMLoop(unsigned short a_usLoopCount);
+signed char ispVMBitShift(signed char mode, unsigned short bits);
+void ispVMComment(unsigned short a_usCommentSize);
+void ispVMHeader(unsigned short a_usHeaderSize);
+signed char ispVMLCOUNT(unsigned short a_usCountSize);
+void ispVMClocks(unsigned short Clocks);
+void ispVMBypass(signed char ScanType, unsigned short Bits);
+void ispVMStateMachine(signed char NextState);
+void ispVMStart();
+void ispVMEnd();
+signed char ispVMSend(unsigned short int);
+signed char ispVMRead(unsigned short int);
+signed char ispVMReadandSave(unsigned short int);
+signed char ispVMProcessLVDS(unsigned short a_usLVDSCount);
+
+/***************************************************************
+*
+* External variables and functions in ispvm_ui.c module
+*
+***************************************************************/
+extern void vme_out_char(unsigned char charOut);
+extern void vme_out_hex(unsigned char hexOut);
+extern void vme_out_string(char *stringOut);
+extern unsigned char GetByte();
+extern void ispVMMemManager(signed char types, unsigned short size);
+
+/***************************************************************
+*
+* External variables and functions in hardware.c module
+*
+***************************************************************/
+extern void ispVMDelay(unsigned short int a_usMicroSecondDelay);
+extern unsigned char readPort();
+extern void writePort(unsigned char pins, unsigned char value);
+extern void sclock();
+extern signed char g_cCurrentJTAGState;
+#ifdef VME_DEBUG
+
+/***************************************************************
+*
+* GetState
+*
+* Returns the state as a string based on the opcode. Only used
+* for debugging purposes.
+*
+***************************************************************/
+
+const char* GetState(unsigned char a_ucState)
+{
+ switch (a_ucState) {
+ case RESET:
+ return ("RESET");
+ case IDLE:
+ return ("IDLE");
+ case IRPAUSE:
+ return ("IRPAUSE");
+ case DRPAUSE:
+ return ("DRPAUSE");
+ case SHIFTIR:
+ return ("SHIFTIR");
+ case SHIFTDR:
+ return ("SHIFTDR");
+ case DRCAPTURE: /* 11/15/05 support DRCAPTURE*/
+ return ("DRCAPTURE");
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/***************************************************************
+*
+* PrintData
+*
+* Prints the data. Only used for debugging purposes.
+*
+***************************************************************/
+
+void PrintData(unsigned short a_iDataSize, unsigned char *a_pucData)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short usByteSize = 0;
+ unsigned short usBitIndex = 0;
+ signed short usByteIndex = 0;
+ unsigned char ucByte = 0;
+ unsigned char ucFlipByte = 0;
+
+ if (a_iDataSize % 8) {
+ //09/11/07 NN Type cast mismatch variables
+ usByteSize = (unsigned short)(a_iDataSize / 8 + 1);
+ } else {
+ //09/11/07 NN Type cast mismatch variables
+ usByteSize = (unsigned short)(a_iDataSize / 8);// 4
+ }
+ printf("(");
+ //09/11/07 NN Type cast mismatch variables
+ for (usByteIndex = (signed short)(usByteSize - 1); usByteIndex >= 0; usByteIndex--) {
+ ucByte = a_pucData[usByteIndex];
+ ucFlipByte = 0x00;
+
+ /***************************************************************
+ *
+ * Flip each byte.
+ *
+ ***************************************************************/
+
+ for (usBitIndex = 0; usBitIndex < 8; usBitIndex++) {
+ ucFlipByte <<= 1;
+ if (ucByte & 0x1) {
+ ucFlipByte |= 0x1;
+ }
+
+ ucByte >>= 1;
+ }
+
+ /***************************************************************
+ *
+ * Print the flipped byte.
+ *
+ ***************************************************************/
+
+ printf("%.02X", ucFlipByte);
+ if ((usByteSize - usByteIndex) % 40 == 39) {
+ printf("\n\t\t");
+ }
+ if (usByteIndex < 0)
+ break;
+ }
+ printf(")");
+}
+#endif //VME_DEBUG
+
+/***************************************************************
+*
+* ispVMDataSize
+*
+* Returns a VME-encoded number, usually used to indicate the
+* bit length of an SIR/SDR command.
+*
+***************************************************************/
+
+long int ispVMDataSize()
+{
+ //09/11/07 NN added local variables initialization
+ long int iSize = 0;
+ signed char cCurrentByte = 0;
+ signed char cIndex = 0;
+ cIndex = 0;
+
+ while ((cCurrentByte = GetByte()) & 0x80) {
+ iSize |= ((long int)(cCurrentByte & 0x7F)) << cIndex;
+ cIndex += 7;
+ }
+ iSize |= ((long int)(cCurrentByte & 0x7F)) << cIndex;
+
+ return iSize;
+}
+
+/***************************************************************
+*
+* ispVMCode
+*
+* This is the heart of the embedded engine. All the high-level opcodes
+* are extracted here. Once they have been identified, then it
+* will call other functions to handle the processing.
+*
+***************************************************************/
+
+signed char ispVMCode()
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short iRepeatSize = 0;
+ signed char cOpcode = 0;
+ signed char cRetCode = 0;
+ unsigned char ucState = 0;
+ unsigned short usDelay = 0;
+ unsigned short usToggle = 0;
+ unsigned char usByte = 0;
+
+ /***************************************************************
+ *
+ * Check the compression flag only if this is the first time
+ * this function is entered. Do not check the compression flag if
+ * it is being called recursively from other functions within
+ * the embedded engine.
+ *
+ ***************************************************************/
+
+ if (!(g_usDataType & LHEAP_IN) && !(g_usDataType & HEAP_IN)) {
+ usByte = GetByte();
+ if (usByte == 0xf1) {
+ g_usDataType |= COMPRESS;
+ } else if (usByte == 0xf2) {
+ g_usDataType &= ~COMPRESS;
+ } else {
+ return VME_INVALID_FILE;
+ }
+ }
+
+ /***************************************************************
+ *
+ * Begin looping through all the VME opcodes.
+ *
+ ***************************************************************/
+ while ((cOpcode = GetByte()) >= 0) {
+ switch (cOpcode) {
+ case STATE:
+
+ /***************************************************************
+ *
+ * Step the JTAG state machine.
+ *
+ ***************************************************************/
+
+ ucState = GetByte();
+ /***************************************************************
+ *
+ * Step the JTAG state machine to DRCAPTURE to support Looping.
+ *
+ ***************************************************************/
+
+ if ((g_usDataType & LHEAP_IN) &&
+ (ucState == DRPAUSE) &&
+ (g_cCurrentJTAGState == ucState)) {
+ ispVMStateMachine(DRCAPTURE);
+ }
+
+ ispVMStateMachine(ucState);
+
+#ifdef VME_DEBUG
+ if (g_usDataType & LHEAP_IN) {
+ printf("LDELAY %s ", GetState(ucState));
+ } else {
+ printf("STATE %s;\n", GetState(ucState));
+ }
+#endif //VME_DEBUG
+ break;
+ case SIR:
+ case SDR:
+ case XSDR:
+
+#ifdef VME_DEBUG
+ switch (cOpcode) {
+ case SIR:
+ printf("SIR ");
+ break;
+ case SDR:
+ case XSDR:
+ if (g_usDataType & LHEAP_IN) {
+ printf("LSDR ");
+ } else {
+ printf("SDR ");
+ }
+ break;
+ }
+#endif //VME_DEBUG
+ /***************************************************************
+ *
+ * Shift in data into the device.
+ *
+ ***************************************************************/
+ cRetCode = ispVMShift(cOpcode);
+ if (cRetCode != 0) {
+ return (cRetCode);
+ }
+ break;
+ case WAIT:
+
+ /***************************************************************
+ *
+ * Observe delay.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ usDelay = (unsigned short)ispVMDataSize();
+ ispVMDelay(usDelay);
+
+#ifdef VME_DEBUG
+ if (usDelay & 0x8000) {
+
+ /***************************************************************
+ *
+ * Since MSB is set, the delay time must be decoded to
+ * millisecond. The SVF2VME encodes the MSB to represent
+ * millisecond.
+ *
+ ***************************************************************/
+
+ usDelay &= ~0x8000;
+ if (g_usDataType & LHEAP_IN) {
+ printf("%.2E SEC;\n", (float)usDelay / 1000);
+ } else {
+ printf("RUNTEST %.2E SEC;\n", (float)usDelay / 1000);
+ }
+ } else {
+
+ /***************************************************************
+ *
+ * Since MSB is not set, the delay time is given as microseconds.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & LHEAP_IN) {
+ printf("%.2E SEC;\n", (float)usDelay / 1000000);
+ } else {
+ printf("RUNTEST %.2E SEC;\n", (float)usDelay / 1000000);
+ }
+ }
+#endif //VME_DEBUG
+ break;
+ case TCK:
+
+ /***************************************************************
+ *
+ * Issue clock toggles.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ usToggle = (unsigned short)ispVMDataSize();
+ ispVMClocks(usToggle);
+
+#ifdef VME_DEBUG
+ printf("RUNTEST %d TCK;\n", usToggle);
+#endif //VME_DEBUG
+ break;
+ case ENDDR:
+
+ /***************************************************************
+ *
+ * Set the ENDDR.
+ *
+ ***************************************************************/
+
+ g_ucEndDR = GetByte();
+
+#ifdef VME_DEBUG
+ printf("ENDDR %s;\n", GetState(g_ucEndDR));
+#endif //VME_DEBUG
+ break;
+ case ENDIR:
+
+ /***************************************************************
+ *
+ * Set the ENDIR.
+ *
+ ***************************************************************/
+
+ g_ucEndIR = GetByte();
+
+#ifdef VME_DEBUG
+ printf("ENDIR %s;\n", GetState(g_ucEndIR));
+#endif //VME_DEBUG
+ break;
+ case HIR:
+ case TIR:
+ case HDR:
+ case TDR:
+
+#ifdef VME_DEBUG
+ switch (cOpcode) {
+ case HIR:
+ printf("HIR ");
+ break;
+ case TIR:
+ printf("TIR ");
+ break;
+ case HDR:
+ printf("HDR ");
+ break;
+ case TDR:
+ printf("TDR ");
+ break;
+ }
+#endif //VME_DEBUG
+
+ /***************************************************************
+ *
+ * Set the header/trailer of the device in order to bypass
+ * successfully.
+ *
+ ***************************************************************/
+
+ cRetCode = ispVMAmble(cOpcode);
+ if (cRetCode != 0) {
+ return (cRetCode);
+ }
+
+#ifdef VME_DEBUG
+ printf(";\n");
+#endif //VME_DEBUG
+ break;
+ case MEM:
+
+ /***************************************************************
+ *
+ * The maximum RAM required to support processing one row of the
+ * VME file.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ g_usMaxSize = (unsigned short)ispVMDataSize();
+
+#ifdef VME_DEBUG
+ printf("// MEMSIZE %d\n", g_usMaxSize);
+#endif //VME_DEBUG
+ break;
+ case VENDOR:
+
+ /***************************************************************
+ *
+ * Set the VENDOR type.
+ *
+ ***************************************************************/
+
+ cOpcode = GetByte();
+ switch (cOpcode) {
+ case LATTICE:
+#ifdef VME_DEBUG
+ printf("// VENDOR LATTICE\n");
+#endif //VME_DEBUG
+ g_cVendor = LATTICE;
+ break;
+ case ALTERA:
+#ifdef VME_DEBUG
+ printf("// VENDOR ALTERA\n");
+#endif //VME_DEBUG
+ g_cVendor = ALTERA;
+ break;
+ case XILINX:
+#ifdef VME_DEBUG
+ printf("// VENDOR XILINX\n");
+#endif //VME_DEBUG
+ g_cVendor = XILINX;
+ break;
+ default:
+ break;
+ }
+ break;
+ case SETFLOW:
+
+ /***************************************************************
+ *
+ * Set the flow control. Flow control determines the personality
+ * of the embedded engine.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ g_usFlowControl |= (unsigned short)ispVMDataSize();
+ break;
+ case RESETFLOW:
+
+ /***************************************************************
+ *
+ * Unset the flow control.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ g_usFlowControl &= (unsigned short)~(ispVMDataSize());
+ break;
+ case HEAP:
+
+ /***************************************************************
+ *
+ * Allocate heap size to store loops.
+ *
+ ***************************************************************/
+
+ cRetCode = GetByte();
+ if (cRetCode != SECUREHEAP) {
+ return VME_INVALID_FILE;
+ }
+ //09/11/07 NN Type cast mismatch variables
+ g_iHEAPSize = (unsigned short)ispVMDataSize();
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the HEAP buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_iHEAPSize > g_usHeapSize) {
+ g_usHeapSize = g_iHEAPSize;
+ }
+
+ ispVMMemManager(HEAP, (unsigned short)g_iHEAPSize);
+ break;
+ case REPEAT:
+
+ /***************************************************************
+ *
+ * Execute loops.
+ *
+ ***************************************************************/
+
+ g_usRepeatLoops = 0;
+
+ //09/11/07 NN Type cast mismatch variables
+ iRepeatSize = (unsigned short)ispVMDataSize();
+
+ cRetCode = ispVMLoop((unsigned short)iRepeatSize);
+ if (cRetCode != 0) {
+ return (cRetCode);
+ }
+ break;
+ case ENDLOOP:
+
+ /***************************************************************
+ *
+ * Exit point from processing loops.
+ *
+ ***************************************************************/
+
+ return (cRetCode);
+ case ENDVME:
+
+ /***************************************************************
+ *
+ * The only valid exit point that indicates end of programming.
+ *
+ ***************************************************************/
+
+ return (cRetCode);
+ case SHR:
+
+ /***************************************************************
+ *
+ * Right-shift address.
+ *
+ ***************************************************************/
+
+ g_usFlowControl |= SHIFTRIGHT;
+
+ //09/11/07 NN Type cast mismatch variables
+ g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte());
+ break;
+ case SHL:
+
+ /***************************************************************
+ *
+ * Left-shift address.
+ *
+ ***************************************************************/
+
+ g_usFlowControl |= SHIFTLEFT;
+
+ //09/11/07 NN Type cast mismatch variables
+ g_usShiftValue = (unsigned short)(g_usRepeatLoops * (unsigned short)GetByte());
+ break;
+ case FREQUENCY:
+
+ /***************************************************************
+ *
+ * Set the frequency.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ g_iFrequency = (int)(ispVMDataSize());
+ //10/23/08 NN changed to check if the frequency smaller than 1000
+ if (g_iFrequency >= 1000) {
+ g_iFrequency = g_iFrequency / 1000;
+ if (g_iFrequency == 1)
+ g_iFrequency = 1000;
+#ifdef VME_DEBUG
+ printf("FREQUENCY %.2E HZ;\n", (float)g_iFrequency * 1000);
+#endif //VME_DEBUG
+ } else {
+ if (g_iFrequency == 0)
+ g_iFrequency = 1000;
+#ifdef VME_DEBUG
+ printf("FREQUENCY %.2E HZ;\n", (float)g_iFrequency);
+#endif //VME_DEBUG
+ }
+ break;
+ case LCOUNT:
+
+ /***************************************************************
+ *
+ * Process LCOUNT command.
+ *
+ ***************************************************************/
+
+ cRetCode = ispVMLCOUNT((unsigned short)ispVMDataSize());
+ if (cRetCode != 0) {
+ return (cRetCode);
+ }
+ break;
+ case VUES:
+
+ /***************************************************************
+ *
+ * Set the flow control to verify USERCODE.
+ *
+ ***************************************************************/
+
+ g_usFlowControl |= VERIFYUES;
+ break;
+ case COMMENT:
+
+ /***************************************************************
+ *
+ * Display comment.
+ *
+ ***************************************************************/
+
+ ispVMComment((unsigned short)ispVMDataSize());
+ break;
+ case LVDS:
+
+ /***************************************************************
+ *
+ * Process LVDS command.
+ *
+ ***************************************************************/
+
+ ispVMProcessLVDS((unsigned short)ispVMDataSize());
+ break;
+ case HEADER:
+
+ /***************************************************************
+ *
+ * Discard header.
+ *
+ ***************************************************************/
+
+ ispVMHeader((unsigned short)ispVMDataSize());
+ break;
+ /* 03/14/06 Support Toggle ispENABLE signal*/
+ case ispEN:
+ ucState = GetByte();
+ if ((ucState == ON) || (ucState == 0x01))
+ writePort(JTAG_ENABLE, 0x01);
+ else
+ writePort(JTAG_ENABLE, 0x00);
+ ispVMDelay(1);
+ break;
+ /* 05/24/06 support Toggle TRST pin*/
+ case TRST:
+ ucState = GetByte();
+ if (ucState == 0x01)
+ writePort(JTAG_TRST, 0x01);
+ else
+ writePort(JTAG_TRST, 0x00);
+ ispVMDelay(1);
+ break;
+ default:
+
+ /***************************************************************
+ *
+ * Invalid opcode encountered.
+ *
+ ***************************************************************/
+
+#ifdef VME_DEBUG
+ printf("\nINVALID OPCODE: 0x%.2X\n", cOpcode);
+#endif //VME_DEBUG
+
+ return VME_INVALID_FILE;
+ }
+ }
+
+ /***************************************************************
+ *
+ * Invalid exit point. Processing the token 'ENDVME' is the only
+ * valid way to exit the embedded engine.
+ *
+ ***************************************************************/
+
+ return (VME_INVALID_FILE);
+}
+
+/***************************************************************
+*
+* ispVMDataCode
+*
+* Processes the TDI/TDO/MASK/DMASK etc of an SIR/SDR command.
+*
+***************************************************************/
+
+signed char ispVMDataCode()
+{
+ //09/11/07 NN added local variables initialization
+ signed char cDataByte = 0;
+ signed char siDataSource = 0; /*source of data from file by default*/
+
+ if (g_usDataType & HEAP_IN) {
+ siDataSource = 1; /*the source of data from memory*/
+ }
+
+ /****************************************************************************
+ *
+ * Clear the data type register.
+ *
+ *****************************************************************************/
+
+ g_usDataType &= ~(MASK_DATA + TDI_DATA + TDO_DATA + DMASK_DATA + CMASK_DATA);
+
+ /****************************************************************************
+ *
+ * Iterate through SIR/SDR command and look for TDI, TDO, MASK, etc.
+ *
+ *****************************************************************************/
+
+ while ((cDataByte = GetByte()) >= 0) {
+
+ ispVMMemManager(cDataByte, g_usMaxSize);
+ switch (cDataByte) {
+ case TDI:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the TDI buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usTDISize) {
+ g_usTDISize = g_usiDataSize;
+ }
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that TDI data is currently being
+ * used. Process the data in the VME file into the TDI buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= TDI_DATA;
+ ispVMData(g_pucInData);
+ break;
+ case XTDO:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the TDO buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usTDOSize) {
+ g_usTDOSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that TDO data is currently being
+ * used.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= TDO_DATA;
+ break;
+ case TDO:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the TDO buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usTDOSize) {
+ g_usTDOSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that TDO data is currently being
+ * used. Process the data in the VME file into the TDO buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= TDO_DATA;
+ ispVMData(g_pucOutData);
+ break;
+ case MASK:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the MASK buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usMASKSize) {
+ g_usMASKSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that MASK data is currently being
+ * used. Process the data in the VME file into the MASK buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= MASK_DATA;
+ ispVMData(g_pucOutMaskData);
+ break;
+ case DMASK:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the DMASK buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usDMASKSize) {
+ g_usDMASKSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that DMASK data is currently being
+ * used. Process the data in the VME file into the DMASK buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= DMASK_DATA;
+ ispVMData(g_pucOutDMaskData);
+ break;
+ case CMASK:
+
+ /****************************************************************************
+ *
+ * Updated data type register to indicate that CMASK data is currently being
+ * used. Process the data in the VME file into the CMASK buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= CMASK_DATA;
+ ispVMData(g_pucOutMaskData);
+ break;
+ case CONTINUE:
+ return (0);
+ default:
+
+ /****************************************************************************
+ *
+ * Encountered invalid opcode.
+ *
+ *****************************************************************************/
+
+ return (VME_INVALID_FILE);
+ }
+
+ switch (cDataByte) {
+ case TDI:
+
+ /****************************************************************************
+ *
+ * Left bit shift. Used when performing algorithm looping.
+ *
+ *****************************************************************************/
+
+ if (g_usFlowControl & SHIFTLEFT) {
+ ispVMBitShift(SHL, g_usShiftValue);
+ g_usFlowControl &= ~SHIFTLEFT;
+ }
+
+ /****************************************************************************
+ *
+ * Right bit shift. Used when performing algorithm looping.
+ *
+ *****************************************************************************/
+
+ if (g_usFlowControl & SHIFTRIGHT) {
+ ispVMBitShift(SHR, g_usShiftValue);
+ g_usFlowControl &= ~SHIFTRIGHT;
+ }
+ default:
+ break;
+ }
+
+ if (siDataSource) {
+ g_usDataType |= HEAP_IN; /*restore data from memory*/
+ }
+ }
+
+ if (siDataSource) { /*fetch data from heap memory upon return*/
+ g_usDataType |= HEAP_IN;
+ }
+
+ if (cDataByte < 0) {
+
+ /****************************************************************************
+ *
+ * Encountered invalid opcode.
+ *
+ *****************************************************************************/
+
+ return (VME_INVALID_FILE);
+ } else {
+ return (0);
+ }
+}
+
+/***************************************************************
+*
+* ispVMData
+* Extract one row of data operand from the current data type opcode. Perform
+* the decompression if necessary. Extra RAM is not required for the
+* decompression process. The decompression scheme employed in this module
+* is on row by row basis. The format of the data stream:
+* [compression code][compressed data stream]
+* 0x00 --No compression
+* 0x01 --Compress by 0x00.
+* Example:
+* Original stream: 0x000000000000000000000001
+* Compressed stream: 0x01000901
+* Detail: 0x01 is the code, 0x00 is the key,
+* 0x09 is the count of 0x00 bytes,
+* 0x01 is the uncompressed byte.
+* 0x02 --Compress by 0xFF.
+* Example:
+* Original stream: 0xFFFFFFFFFFFFFFFFFFFFFF01
+* Compressed stream: 0x02FF0901
+* Detail: 0x02 is the code, 0xFF is the key,
+* 0x09 is the count of 0xFF bytes,
+* 0x01 is the uncompressed byte.
+* 0x03
+* : :
+* 0xFE -- Compress by nibble blocks.
+* Example:
+* Original stream: 0x84210842108421084210
+* Compressed stream: 0x0584210
+* Detail: 0x05 is the code, means 5 nibbles block.
+* 0x84210 is the 5 nibble blocks.
+* The whole row is 80 bits given by g_usiDataSize.
+* The number of times the block repeat itself
+* is found by g_usiDataSize/(4*0x05) which is 4.
+* 0xFF -- Compress by the most frequently happen byte.
+* Example:
+* Original stream: 0x04020401030904040404
+* Compressed stream: 0xFF04(0,1,0x02,0,1,0x01,1,0x03,1,0x09,0,0,0)
+* or: 0xFF044090181C240
+* Detail: 0xFF is the code, 0x04 is the key.
+* a bit of 0 represent the key shall be put into
+* the current bit position and a bit of 1
+* represent copying the next of 8 bits of data
+* in.
+*
+***************************************************************/
+
+void ispVMData(unsigned char *ByteData)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short size = 0;
+ unsigned short i, j, m, getData = 0;
+ unsigned char cDataByte = 0;
+ unsigned char compress = 0;
+ unsigned short FFcount = 0;
+ unsigned char compr_char = 0xFF;
+ unsigned short index = 0;
+ signed char compression = 0;
+
+ /*convert number in bits to bytes*/
+ if (g_usiDataSize % 8 > 0) {
+ //09/11/07 NN Type cast mismatch variables
+ size = (unsigned short)(g_usiDataSize / 8 + 1);
+ } else {
+ //09/11/07 NN Type cast mismatch variables
+ size = (unsigned short)(g_usiDataSize / 8);
+ }
+
+ /* If there is compression, then check if compress by key of 0x00 or 0xFF
+ or by other keys or by nibble blocks*/
+
+ if (g_usDataType & COMPRESS) {
+ compression = 1;
+ if (((compress = GetByte()) == VAR) && (g_usDataType & HEAP_IN)) {
+ getData = 1;
+ g_usDataType &= ~(HEAP_IN);
+ compress = GetByte();
+ }
+
+ switch (compress) {
+ case 0x00:
+ /* No compression */
+ compression = 0;
+ break;
+ case 0x01:
+ /* Compress by byte 0x00 */
+ compr_char = 0x00;
+ break;
+ case 0x02:
+ /* Compress by byte 0xFF */
+ compr_char = 0xFF;
+ break;
+ case 0xFF:
+ /* Huffman encoding */
+ compr_char = GetByte();
+ i = 8;
+ for (index = 0; index < size; index++) {
+ ByteData[index] = 0x00;
+ if (i > 7) {
+ cDataByte = GetByte();
+ i = 0;
+ }
+ if ((cDataByte << i++) & 0x80)
+ m = 8;
+ else {
+ ByteData[index] = compr_char;
+ m = 0;
+ }
+
+ for (j = 0; j < m; j++) {
+ if (i > 7) {
+ cDataByte = GetByte();
+ i = 0;
+ }
+ ByteData[index] |= ((cDataByte << i++) & 0x80) >> j;
+ }
+ }
+ size = 0;
+ break;
+ default:
+ for (index = 0; index < size; index++)
+ ByteData[index] = 0x00;
+ for (index = 0; index < compress; index++) {
+ if (index % 2 == 0)
+ cDataByte = GetByte();
+ for (i = 0; i < size * 2 / compress; i++) {
+ //09/11/07 NN Type cast mismatch variables
+ j = (unsigned short)(index + (i * (unsigned short)compress));
+ /*clear the nibble to zero first*/
+ if (j % 2) {
+ if (index % 2)
+ ByteData[j / 2] |= cDataByte & 0x0F;
+ else
+ ByteData[j / 2] |= cDataByte >> 4;
+ } else {
+ if (index % 2)
+ ByteData[j / 2] |= cDataByte << 4;
+ else
+ ByteData[j / 2] |= cDataByte & 0xF0;
+ }
+ }
+ }
+ size = 0;
+ break;
+ }
+ }
+
+ FFcount = 0;
+
+ /* Decompress by byte 0x00 or 0xFF */
+ for (index = 0; index < size; index++) {
+ if (FFcount <= 0) {
+ cDataByte = GetByte();
+ if ((cDataByte == VAR) && (g_usDataType & HEAP_IN) && !getData && !(g_usDataType & COMPRESS)) {
+ getData = 1;
+ g_usDataType &= ~(HEAP_IN);
+ cDataByte = GetByte();
+ }
+ ByteData[index] = cDataByte;
+ if ((compression) && (cDataByte == compr_char)) /*decompression is on*/
+ //09/11/07 NN Type cast mismatch variables
+ FFcount = (unsigned short)ispVMDataSize(); /*The number of 0xFF or 0x00 bytes*/
+ } else {
+ FFcount--; /*Use up the 0xFF chain first*/
+ ByteData[index] = compr_char;
+ }
+ }
+
+ if (getData) {
+ g_usDataType |= HEAP_IN;
+ getData = 0;
+ }
+}
+
+/***************************************************************
+*
+* ispVMShift
+*
+* Processes the SDR/XSDR/SIR commands.
+*
+***************************************************************/
+
+signed char ispVMShift(signed char a_cCode)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short iDataIndex = 0;
+ unsigned short iReadLoop = 0;
+ signed char cRetCode = 0;
+
+ cRetCode = 0;
+ //09/11/07 NN Type cast mismatch variables
+ g_usiDataSize = (unsigned short)ispVMDataSize();
+
+ g_usDataType &= ~(SIR_DATA + EXPRESS + SDR_DATA); /*clear the flags first*/
+
+ switch (a_cCode) {
+ case SIR:
+ g_usDataType |= SIR_DATA;
+ /* 1/15/04 If performing cascading, then go directly to SHIFTIR. Else,
+ go to IRPAUSE before going to SHIFTIR */
+ if (g_usFlowControl & CASCADE) {
+ ispVMStateMachine(SHIFTIR);
+ } else {
+ ispVMStateMachine(IRPAUSE);
+ ispVMStateMachine(SHIFTIR);
+ if (g_usHeadIR > 0) {
+ ispVMBypass(HIR, g_usHeadIR);
+ sclock();
+ }
+ }
+ break;
+ case XSDR:
+ g_usDataType |= EXPRESS; /*mark simultaneous in and out*/
+ case SDR:
+ g_usDataType |= SDR_DATA;
+ /* 1/15/04 If already in SHIFTDR, then do not move state or shift in header.
+ This would imply that the previously shifted frame was a cascaded frame. */
+ if (g_cCurrentJTAGState != SHIFTDR) {
+ /* 1/15/04 If performing cascading, then go directly to SHIFTDR. Else,
+ go to DRPAUSE before going to SHIFTDR */
+ if (g_usFlowControl & CASCADE) {
+ if (g_cCurrentJTAGState == DRPAUSE) {
+ ispVMStateMachine(SHIFTDR);
+ /* 1/15/04 If cascade flag has been set and the current state is
+ DRPAUSE, this implies that the first cascaded frame is about to
+ be shifted in. The header must be shifted prior to shifting
+ the first cascaded frame. */
+ if (g_usHeadDR > 0) {
+ ispVMBypass(HDR, g_usHeadDR);
+ sclock();
+ }
+ } else {
+ ispVMStateMachine(SHIFTDR);
+ }
+ } else {
+ ispVMStateMachine(DRPAUSE);
+ ispVMStateMachine(SHIFTDR);
+ if (g_usHeadDR > 0) {
+ ispVMBypass(HDR, g_usHeadDR);
+ sclock();
+ }
+ }
+ }
+ break;
+ default:
+ return (VME_INVALID_FILE);
+ }
+
+ cRetCode = ispVMDataCode();
+ if (cRetCode != 0) {
+ return (VME_INVALID_FILE);
+ }
+
+#ifdef VME_DEBUG
+ if (g_usDataType & TDI_DATA) {
+ printf("\n\t\tTDI ");
+ PrintData(g_usiDataSize, g_pucInData);
+ }
+
+ if (g_usDataType & TDO_DATA) {
+ printf("\n\t\tTDO ");
+ PrintData(g_usiDataSize, g_pucOutData);
+ }
+
+ if (g_usDataType & MASK_DATA) {
+ printf("\n\t\tMASK ");
+ PrintData(g_usiDataSize, g_pucOutMaskData);
+ }
+
+ if (g_usDataType & DMASK_DATA) {
+ printf("\n\t\tDMASK ");
+ PrintData(g_usiDataSize, g_pucOutDMaskData);
+ }
+
+ printf(";\n");
+#endif //VME_DEBUG
+ if (g_usDataType & TDO_DATA || g_usDataType & DMASK_DATA) {
+ if (g_usDataType & DMASK_DATA) {
+
+ cRetCode = ispVMReadandSave(g_usiDataSize);
+
+ if (!cRetCode) {
+ if (g_usTailDR > 0) {
+ sclock();
+ ispVMBypass(TDR, g_usTailDR);
+ }
+ ispVMStateMachine(DRPAUSE);
+ ispVMStateMachine(SHIFTDR);
+ if (g_usHeadDR > 0) {
+ ispVMBypass(HDR, g_usHeadDR);
+ sclock();
+ }
+ for (iDataIndex = 0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++)
+ g_pucInData[iDataIndex] = g_pucOutData[iDataIndex];
+ g_usDataType &= ~(TDO_DATA + DMASK_DATA);
+ cRetCode = ispVMSend(g_usiDataSize);
+ }
+ } else {
+
+ cRetCode = ispVMRead(g_usiDataSize);
+ if (cRetCode == -1 && g_cVendor == XILINX) {
+ for (iReadLoop = 0; iReadLoop < 30; iReadLoop++) {
+ cRetCode = ispVMRead(g_usiDataSize);
+ if (!cRetCode) {
+ break;
+ } else {
+ ispVMStateMachine(DRPAUSE); /*Always DRPAUSE*/
+ /*Bypass other devices when appropriate*/
+ ispVMBypass(TDR, g_usTailDR);
+ ispVMStateMachine(g_ucEndDR);
+ ispVMStateMachine(IDLE);
+ ispVMDelay(1000);
+ }
+ }
+ }
+ }
+ } else { /*TDI only*/
+ cRetCode = ispVMSend(g_usiDataSize);
+
+ }
+
+ /*transfer the input data to the output buffer for the next verify*/
+ if ((g_usDataType & EXPRESS) || (a_cCode == SDR)) {
+ if (g_pucOutData) {
+ for (iDataIndex = 0; iDataIndex < g_usiDataSize / 8 + 1; iDataIndex++)
+ g_pucOutData[iDataIndex] = g_pucInData[iDataIndex];
+ }
+ }
+
+ switch (a_cCode) {
+ case SIR:
+ /* 1/15/04 If not performing cascading, then shift ENDIR */
+ if (!(g_usFlowControl & CASCADE)) {
+ if (g_usTailIR > 0) {
+ sclock();
+ ispVMBypass(TIR, g_usTailIR);
+ }
+ ispVMStateMachine(g_ucEndIR);
+ }
+ break;
+ case XSDR:
+ case SDR:
+ /* 1/15/04 If not performing cascading, then shift ENDDR */
+ if (!(g_usFlowControl & CASCADE)) {
+ if (g_usTailDR > 0) {
+ sclock();
+ ispVMBypass(TDR, g_usTailDR);
+ }
+ ispVMStateMachine(g_ucEndDR);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return (cRetCode);
+}
+
+/***************************************************************
+*
+* ispVMAmble
+*
+* This routine is to extract Header and Trailer parameter for SIR and
+* SDR operations.
+*
+* The Header and Trailer parameter are the pre-amble and post-amble bit
+* stream need to be shifted into TDI or out of TDO of the devices. Mostly
+* is for the purpose of bypassing the leading or trailing devices. ispVM
+* supports only shifting data into TDI to bypass the devices.
+*
+* For a single device, the header and trailer parameters are all set to 0
+* as default by ispVM. If it is for multiple devices, the header and trailer
+* value will change as specified by the VME file.
+*
+***************************************************************/
+
+signed char ispVMAmble(signed char Code)
+{
+ signed char compress = 0;
+ //09/11/07 NN Type cast mismatch variables
+ g_usiDataSize = (unsigned short)ispVMDataSize();
+
+#ifdef VME_DEBUG
+ printf("%d", g_usiDataSize);
+#endif //VME_DEBUG
+
+ if (g_usiDataSize) {
+
+ /****************************************************************************
+ *
+ * Discard the TDI byte and set the compression bit in the data type register
+ * to false if compression is set because TDI data after HIR/HDR/TIR/TDR is not
+ * compressed.
+ *
+ *****************************************************************************/
+
+ GetByte();
+ if (g_usDataType & COMPRESS) {
+ g_usDataType &= ~(COMPRESS);
+ compress = 1;
+ }
+ }
+
+ switch (Code) {
+ case HIR:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the HIR buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usHIRSize) {
+ g_usHIRSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Assign the HIR value and allocate memory.
+ *
+ *****************************************************************************/
+
+ g_usHeadIR = g_usiDataSize;
+ if (g_usHeadIR) {
+ ispVMMemManager(HIR, g_usHeadIR);
+ ispVMData(g_pucHIRData);
+
+#ifdef VME_DEBUG
+ printf(" TDI ");
+ PrintData(g_usHeadIR, g_pucHIRData);
+#endif //VME_DEBUG
+ }
+ break;
+ case TIR:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the TIR buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usTIRSize) {
+ g_usTIRSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Assign the TIR value and allocate memory.
+ *
+ *****************************************************************************/
+
+ g_usTailIR = g_usiDataSize;
+ if (g_usTailIR) {
+ ispVMMemManager(TIR, g_usTailIR);
+ ispVMData(g_pucTIRData);
+
+#ifdef VME_DEBUG
+ printf(" TDI ");
+ PrintData(g_usTailIR, g_pucTIRData);
+#endif //VME_DEBUG
+ }
+ break;
+ case HDR:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the HDR buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usHDRSize) {
+ g_usHDRSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Assign the HDR value and allocate memory.
+ *
+ *****************************************************************************/
+
+ g_usHeadDR = g_usiDataSize;
+ if (g_usHeadDR) {
+ ispVMMemManager(HDR, g_usHeadDR);
+ ispVMData(g_pucHDRData);
+
+#ifdef VME_DEBUG
+ printf(" TDI ");
+ PrintData(g_usHeadDR, g_pucHDRData);
+#endif //VME_DEBUG
+ }
+ break;
+ case TDR:
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the TDR buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usiDataSize > g_usTDRSize) {
+ g_usTDRSize = g_usiDataSize;
+ }
+
+ /****************************************************************************
+ *
+ * Assign the TDR value and allocate memory.
+ *
+ *****************************************************************************/
+
+ g_usTailDR = g_usiDataSize;
+ if (g_usTailDR) {
+ ispVMMemManager(TDR, g_usTailDR);
+ ispVMData(g_pucTDRData);
+
+#ifdef VME_DEBUG
+ printf(" TDI ");
+ PrintData(g_usTailDR, g_pucTDRData);
+#endif //VME_DEBUG
+ }
+ break;
+ default:
+ break;
+ }
+
+ /****************************************************************************
+ *
+ * Re-enable compression if it was previously set.
+ *
+ *****************************************************************************/
+
+ if (compress) {
+ g_usDataType |= COMPRESS;
+ }
+
+ if (g_usiDataSize) {
+ Code = GetByte();
+ if (Code == CONTINUE) {
+ return 0;
+ } else {
+
+ /****************************************************************************
+ *
+ * Encountered invalid opcode.
+ *
+ *****************************************************************************/
+
+ return VME_INVALID_FILE;
+ }
+ }
+
+ return 0;
+}
+
+/***************************************************************
+*
+* ispVMLoop
+*
+* Perform the function call upon by the REPEAT opcode.
+* Memory is to be allocated to store the entire loop from REPEAT to ENDLOOP.
+* After the loop is stored then execution begin. The REPEATLOOP flag is set
+* on the g_usFlowControl register to indicate the repeat loop is in session
+* and therefore fetch opcode from the memory instead of from the file.
+*
+***************************************************************/
+
+signed char ispVMLoop(unsigned short a_usLoopCount)
+{
+ //09/11/07 NN added local variables initialization
+ signed char cRetCode = 0;
+ unsigned short iHeapIndex = 0;
+ unsigned short iLoopIndex = 0;
+
+ g_usShiftValue = 0;
+ for (iHeapIndex = 0; iHeapIndex < g_iHEAPSize; iHeapIndex++) {
+ g_pucHeapMemory[iHeapIndex] = GetByte();
+ }
+
+ if (g_pucHeapMemory[iHeapIndex - 1] != ENDLOOP) {
+ return (VME_INVALID_FILE);
+ }
+
+ g_usFlowControl |= REPEATLOOP;
+ g_usDataType |= HEAP_IN;
+
+ for (iLoopIndex = 0; iLoopIndex < a_usLoopCount; iLoopIndex++) {
+ g_iHeapCounter = 0;
+ cRetCode = ispVMCode();
+ g_usRepeatLoops++;
+ if (cRetCode < 0) {
+ break;
+ }
+ }
+
+ g_usDataType &= ~(HEAP_IN);
+ g_usFlowControl &= ~(REPEATLOOP);
+ return (cRetCode);
+}
+
+/***************************************************************
+*
+* ispVMBitShift
+*
+* Shift the TDI stream left or right by the number of bits. The data in
+* *g_pucInData is of the VME format, so the actual shifting is the reverse of
+* IEEE 1532 or SVF format.
+*
+***************************************************************/
+
+signed char ispVMBitShift(signed char mode, unsigned short bits)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short i = 0;
+ unsigned short size = 0;
+ unsigned short tmpbits = 0;
+
+ if (g_usiDataSize % 8 > 0) {
+ //09/11/07 NN Type cast mismatch variables
+ size = (unsigned short)(g_usiDataSize / 8 + 1);
+ } else {
+ //09/11/07 NN Type cast mismatch variables
+ size = (unsigned short)(g_usiDataSize / 8);
+ }
+
+ switch (mode) {
+ case SHR:
+ for (i = 0; i < size; i++) {
+ if (g_pucInData[i] != 0) {
+ tmpbits = bits;
+ while (tmpbits > 0) {
+ g_pucInData[i] <<= 1;
+ if (g_pucInData[i] == 0) {
+ i--;
+ g_pucInData[i] = 1;
+ }
+ tmpbits--;
+ }
+ }
+ }
+ break;
+ case SHL:
+ for (i = 0; i < size; i++) {
+ if (g_pucInData[i] != 0) {
+ tmpbits = bits;
+ while (tmpbits > 0) {
+ g_pucInData[i] >>= 1;
+ if (g_pucInData[i] == 0) {
+ i--;
+ g_pucInData[i] = 8;
+ }
+ tmpbits--;
+ }
+ }
+ }
+ break;
+ default:
+ return (VME_INVALID_FILE);
+ }
+
+ return (0);
+}
+
+/***************************************************************
+*
+* ispVMComment
+*
+* Displays the SVF comments.
+*
+***************************************************************/
+
+void ispVMComment(unsigned short a_usCommentSize)
+{
+ char cCurByte = 0;
+ for (; a_usCommentSize > 0; a_usCommentSize--) {
+ /****************************************************************************
+ *
+ * Print character to the terminal.
+ *
+ *****************************************************************************/
+ cCurByte = GetByte();
+ vme_out_char(cCurByte);
+ }
+ cCurByte = '\n';
+ vme_out_char(cCurByte);
+}
+
+/***************************************************************
+*
+* ispVMHeader
+*
+* Iterate the length of the header and discard it.
+*
+***************************************************************/
+
+void ispVMHeader(unsigned short a_usHeaderSize)
+{
+ for (; a_usHeaderSize > 0; a_usHeaderSize--) {
+ GetByte();
+ }
+}
+
+/***************************************************************
+*
+* ispVMCalculateCRC32
+*
+* Calculate the 32-bit CRC.
+*
+***************************************************************/
+
+void ispVMCalculateCRC32(unsigned char a_ucData)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned char ucIndex = 0;
+ unsigned char ucFlipData = 0;
+ unsigned short usCRCTableEntry = 0;
+ unsigned int crc_table[16] = {
+ 0x0000, 0xCC01, 0xD801,
+ 0x1400, 0xF001, 0x3C00,
+ 0x2800, 0xE401, 0xA001,
+ 0x6C00, 0x7800, 0xB401,
+ 0x5000, 0x9C01, 0x8801,
+ 0x4400
+ };
+
+ for (ucIndex = 0; ucIndex < 8; ucIndex++) {
+ ucFlipData <<= 1;
+ if (a_ucData & 0x01) {
+ ucFlipData |= 0x01;
+ }
+ a_ucData >>= 1;
+ }
+
+ //09/11/07 NN Type cast mismatch variables
+ usCRCTableEntry = (unsigned short)(crc_table[g_usCalculatedCRC & 0xF]);
+ g_usCalculatedCRC = (unsigned short)((g_usCalculatedCRC >> 4) & 0x0FFF);
+ g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[ucFlipData & 0xF]);
+ usCRCTableEntry = (unsigned short)(crc_table[g_usCalculatedCRC & 0xF]);
+ g_usCalculatedCRC = (unsigned short)((g_usCalculatedCRC >> 4) & 0x0FFF);
+ g_usCalculatedCRC = (unsigned short)(g_usCalculatedCRC ^ usCRCTableEntry ^ crc_table[(ucFlipData >> 4) & 0xF]);
+}
+
+/***************************************************************
+*
+* ispVMLCOUNT
+*
+* Process the intelligent programming loops.
+*
+***************************************************************/
+
+signed char ispVMLCOUNT(unsigned short a_usCountSize)
+{
+ unsigned short usContinue = 1;
+ unsigned short usIntelBufferIndex = 0;
+ unsigned short usCountIndex = 0;
+ signed char cRetCode = 0;
+ signed char cRepeatHeap = 0;
+ signed char cOpcode = 0;
+ unsigned char ucState = 0;
+ unsigned short usDelay = 0;
+ unsigned short usToggle = 0;
+
+ g_usIntelBufferSize = (unsigned short)ispVMDataSize();
+
+ /****************************************************************************
+ *
+ * Allocate memory for intel buffer.
+ *
+ *****************************************************************************/
+
+ ispVMMemManager(LHEAP, g_usIntelBufferSize);
+
+ /****************************************************************************
+ *
+ * Store the maximum size of the intelligent buffer. Used to convert VME to HEX.
+ *
+ *****************************************************************************/
+
+ if (g_usIntelBufferSize > g_usLCOUNTSize) {
+ g_usLCOUNTSize = g_usIntelBufferSize;
+ }
+
+ /****************************************************************************
+ *
+ * Copy intel data to the buffer.
+ *
+ *****************************************************************************/
+
+ for (usIntelBufferIndex = 0; usIntelBufferIndex < g_usIntelBufferSize; usIntelBufferIndex++) {
+ g_pucIntelBuffer[usIntelBufferIndex] = GetByte();
+ }
+
+ /****************************************************************************
+ *
+ * Set the data type register to get data from the intelligent data buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType |= LHEAP_IN;
+
+ /****************************************************************************
+ *
+ * If the HEAP_IN flag is set, temporarily unset the flag so data will be
+ * retrieved from the status buffer.
+ *
+ *****************************************************************************/
+
+ if (g_usDataType & HEAP_IN) {
+ g_usDataType &= ~HEAP_IN;
+ cRepeatHeap = 1;
+ }
+
+#ifdef VME_DEBUG
+ printf("LCOUNT %d;\n", a_usCountSize);
+#endif //VME_DEBUG
+
+ /****************************************************************************
+ *
+ * Iterate through the intelligent programming command.
+ *
+ *****************************************************************************/
+
+ for (usCountIndex = 0; usCountIndex < a_usCountSize; usCountIndex++) {
+
+ /****************************************************************************
+ *
+ * Initialize the intel data index to 0 before each iteration.
+ *
+ *****************************************************************************/
+
+ g_usIntelDataIndex = 0;
+ cOpcode = 0;
+ ucState = 0;
+ usDelay = 0;
+ usToggle = 0;
+ usContinue = 1;
+
+ /***************************************************************
+ *
+ * Begin looping through all the VME opcodes.
+ *
+ ***************************************************************/
+ /***************************************************************
+ * 4/1/09 Nguyen replaced the recursive function call codes on
+ * the ispVMLCOUNT function
+ *
+ ***************************************************************/
+ while (usContinue) {
+ cOpcode = GetByte();
+ switch (cOpcode) {
+ case HIR:
+ case TIR:
+ case HDR:
+ case TDR:
+ /***************************************************************
+ *
+ * Set the header/trailer of the device in order to bypass
+ * successfully.
+ *
+ ***************************************************************/
+
+ ispVMAmble(cOpcode);
+ break;
+ case STATE:
+
+ /***************************************************************
+ *
+ * Step the JTAG state machine.
+ *
+ ***************************************************************/
+
+ ucState = GetByte();
+ /***************************************************************
+ *
+ * Step the JTAG state machine to DRCAPTURE to support Looping.
+ *
+ ***************************************************************/
+
+ if ((g_usDataType & LHEAP_IN) &&
+ (ucState == DRPAUSE) &&
+ (g_cCurrentJTAGState == ucState)) {
+ ispVMStateMachine(DRCAPTURE);
+ }
+ ispVMStateMachine(ucState);
+#ifdef VME_DEBUG
+ printf("LDELAY %s ", GetState(ucState));
+#endif //VME_DEBUG
+ break;
+ case SIR:
+#ifdef VME_DEBUG
+ printf("SIR ");
+#endif //VME_DEBUG
+ /***************************************************************
+ *
+ * Shift in data into the device.
+ *
+ ***************************************************************/
+
+ cRetCode = ispVMShift(cOpcode);
+ break;
+ case SDR:
+
+#ifdef VME_DEBUG
+ printf("LSDR ");
+#endif //VME_DEBUG
+ /***************************************************************
+ *
+ * Shift in data into the device.
+ *
+ ***************************************************************/
+
+ cRetCode = ispVMShift(cOpcode);
+ break;
+ case WAIT:
+
+ /***************************************************************
+ *
+ * Observe delay.
+ *
+ ***************************************************************/
+
+ usDelay = (unsigned short)ispVMDataSize();
+ ispVMDelay(usDelay);
+
+#ifdef VME_DEBUG
+ if (usDelay & 0x8000) {
+
+ /***************************************************************
+ *
+ * Since MSB is set, the delay time must be decoded to
+ * millisecond. The SVF2VME encodes the MSB to represent
+ * millisecond.
+ *
+ ***************************************************************/
+
+ usDelay &= ~0x8000;
+ printf("%.2E SEC;\n", (float)usDelay / 1000);
+ } else {
+
+ /***************************************************************
+ *
+ * Since MSB is not set, the delay time is given as microseconds.
+ *
+ ***************************************************************/
+
+ printf("%.2E SEC;\n", (float)usDelay / 1000000);
+ }
+#endif //VME_DEBUG
+ break;
+ case TCK:
+
+ /***************************************************************
+ *
+ * Issue clock toggles.
+ *
+ ***************************************************************/
+
+ usToggle = (unsigned short)ispVMDataSize();
+ ispVMClocks(usToggle);
+
+#ifdef VME_DEBUG
+ printf("RUNTEST %d TCK;\n", usToggle);
+#endif //VME_DEBUG
+ break;
+ case ENDLOOP:
+
+ /***************************************************************
+ *
+ * Exit point from processing loops.
+ *
+ ***************************************************************/
+ usContinue = 0;
+ break;
+
+ case COMMENT:
+
+ /***************************************************************
+ *
+ * Display comment.
+ *
+ ***************************************************************/
+
+ ispVMComment((unsigned short)ispVMDataSize());
+ break;
+ case ispEN:
+ ucState = GetByte();
+ if ((ucState == ON) || (ucState == 0x01))
+ writePort(JTAG_ENABLE, 0x01);
+ else
+ writePort(JTAG_ENABLE, 0x00);
+ ispVMDelay(1);
+ break;
+ case TRST:
+ if (GetByte() == 0x01)
+ writePort(JTAG_TRST, 0x01);
+ else
+ writePort(JTAG_TRST, 0x00);
+ ispVMDelay(1);
+ break;
+ default:
+
+ /***************************************************************
+ *
+ * Invalid opcode encountered.
+ *
+ ***************************************************************/
+
+#ifdef VME_DEBUG
+ printf("\nINVALID OPCODE: 0x%.2X\n", cOpcode);
+#endif //VME_DEBUG
+
+ return VME_INVALID_FILE;
+ }
+ }
+ if (cRetCode >= 0) {
+ /****************************************************************************
+ *
+ * Break if intelligent programming is successful.
+ *
+ *****************************************************************************/
+
+ break;
+ }
+
+ }
+ /****************************************************************************
+ *
+ * If HEAP_IN flag was temporarily disabled, re-enable it before exiting.
+ *
+ *****************************************************************************/
+
+ if (cRepeatHeap) {
+ g_usDataType |= HEAP_IN;
+ }
+
+ /****************************************************************************
+ *
+ * Set the data type register to not get data from the intelligent data buffer.
+ *
+ *****************************************************************************/
+
+ g_usDataType &= ~LHEAP_IN;
+ return cRetCode;
+}
+
+/***************************************************************
+*
+* ispVMClocks
+*
+* Applies the specified number of pulses to TCK.
+*
+***************************************************************/
+
+void ispVMClocks(unsigned short Clocks)
+{
+ unsigned short iClockIndex = 0;
+ for (iClockIndex = 0; iClockIndex < Clocks; iClockIndex++) {
+ sclock();
+ }
+}
+
+/***************************************************************
+*
+* ispVMBypass
+*
+* This procedure takes care of the HIR, HDR, TIR, TDR for the
+* purpose of putting the other devices into Bypass mode. The
+* current state is checked to find out if it is at DRPAUSE or
+* IRPAUSE. If it is at DRPAUSE, perform bypass register scan.
+* If it is at IRPAUSE, scan into instruction registers the bypass
+* instruction.
+*
+***************************************************************/
+
+void ispVMBypass(signed char ScanType, unsigned short Bits)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short iIndex = 0;
+ unsigned short iSourceIndex = 0;
+ unsigned char cBitState = 0;
+ unsigned char cCurByte = 0;
+ unsigned char *pcSource = NULL;
+
+ if (Bits <= 0) {
+ return;
+ }
+
+ switch (ScanType) {
+ case HIR:
+ pcSource = g_pucHIRData;
+ break;
+ case TIR:
+ pcSource = g_pucTIRData;
+ break;
+ case HDR:
+ pcSource = g_pucHDRData;
+ break;
+ case TDR:
+ pcSource = g_pucTDRData;
+ break;
+ default:
+ break;
+ }
+ if (pcSource) {
+ iSourceIndex = 0;
+ cBitState = 0;
+ for (iIndex = 0; iIndex < Bits - 1; iIndex++) {
+ /* Scan instruction or bypass register */
+ if (iIndex % 8 == 0) {
+ cCurByte = pcSource[iSourceIndex++];
+ }
+ cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00);
+ writePort(JTAG_TDI, cBitState);
+ sclock();
+ }
+
+ if (iIndex % 8 == 0) {
+ cCurByte = pcSource[iSourceIndex++];
+ }
+
+ cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00);
+ writePort(JTAG_TDI, cBitState);
+ }
+}
+
+/***************************************************************
+*
+* ispVMStateMachine
+*
+* This procedure steps all devices in the daisy chain from a given
+* JTAG state to the next desirable state. If the next state is TLR,
+* the JTAG state machine is brute forced into TLR by driving TMS
+* high and pulse TCK 6 times.
+*
+***************************************************************/
+
+void ispVMStateMachine(signed char cNextJTAGState)
+{
+ //09/11/07 NN added local variables initialization
+ signed char cPathIndex = 0;
+ signed char cStateIndex = 0;
+ short int found = 0;
+
+ if ((g_cCurrentJTAGState == cNextJTAGState) && (cNextJTAGState != RESET)) {
+ return;
+ }
+
+ for (cStateIndex = 0; cStateIndex < 25; cStateIndex++) {
+ if ((g_cCurrentJTAGState == g_JTAGTransistions[cStateIndex].CurState) && (cNextJTAGState == g_JTAGTransistions[cStateIndex].NextState)) {
+ found = 1;
+ break;
+ }
+ }
+ if (found) {
+ g_cCurrentJTAGState = cNextJTAGState;
+ for (cPathIndex = 0; cPathIndex < g_JTAGTransistions[cStateIndex].Pulses; cPathIndex++) {
+ if ((g_JTAGTransistions[cStateIndex].Pattern << cPathIndex) & 0x80) {
+ writePort(JTAG_TMS, (unsigned char)0x01);
+ } else {
+ writePort(JTAG_TMS, (unsigned char)0x00);
+ }
+ sclock();
+ }
+
+ writePort(JTAG_TDI, 0x00);
+ writePort(JTAG_TMS, 0x00);
+ }
+}
+
+/***************************************************************
+*
+* ispVMStart
+*
+* Enable the port to the device and set the state to RESET (TLR).
+*
+***************************************************************/
+
+void ispVMStart()
+{
+#ifdef VME_DEBUG
+ printf("// ISPVM EMBEDDED ADDED\n");
+ printf("STATE RESET;\n");
+#endif
+
+ ispVMStateMachine(RESET); /*step devices to RESET state*/
+
+}
+
+/***************************************************************
+*
+* ispVMEnd
+*
+* Set the state of devices to RESET to enable the devices and disable
+* the port.
+*
+***************************************************************/
+
+void ispVMEnd()
+{
+#ifdef VME_DEBUG
+ printf("// ISPVM EMBEDDED ADDED\n");
+ printf("STATE RESET;\n");
+ printf("RUNTEST 1.00E-001 SEC;\n");
+#endif
+
+ ispVMStateMachine(RESET); /*step devices to RESET state */
+ ispVMDelay(1000); /*wake up devices*/
+}
+
+/***************************************************************
+*
+* ispVMSend
+*
+* Send the TDI data stream to devices. The data stream can be
+* instructions or data.
+*
+***************************************************************/
+
+signed char ispVMSend(unsigned short a_usiDataSize)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short iIndex = 0;
+ unsigned short iInDataIndex = 0;
+ unsigned char cCurByte = 0;
+ unsigned char cBitState = 0;
+
+ for (iIndex = 0; iIndex < a_usiDataSize - 1; iIndex++) {
+ if (iIndex % 8 == 0) {
+ cCurByte = g_pucInData[iInDataIndex++];
+ }
+ cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00);
+ writePort(JTAG_TDI, cBitState);
+ sclock();
+ }
+
+ if (iIndex % 8 == 0) {
+ /* Take care of the last bit */
+ cCurByte = g_pucInData[iInDataIndex];
+ }
+
+ cBitState = (unsigned char)(((cCurByte << iIndex % 8) & 0x80) ? 0x01 : 0x00);
+
+ writePort(JTAG_TDI, cBitState);
+ if (g_usFlowControl & CASCADE) {
+ /* 1/15/04 Clock in last bit for the first n-1 cascaded frames */
+ sclock();
+ }
+
+ return 0;
+}
+
+/***************************************************************
+*
+* ispVMRead
+*
+* Read the data stream from devices and verify.
+*
+***************************************************************/
+
+signed char ispVMRead(unsigned short a_usiDataSize) //32
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short usDataSizeIndex = 0;
+ unsigned short usErrorCount = 0;
+ unsigned short usLastBitIndex = 0;
+ unsigned char cDataByte = 0;
+ unsigned char cMaskByte = 0;
+ unsigned char cInDataByte = 0;
+ unsigned char cCurBit = 0;
+ unsigned char cByteIndex = 0;
+ unsigned short usBufferIndex = 0;
+ unsigned char ucDisplayByte = 0x00;
+ unsigned char ucDisplayFlag = 0x01;
+ char StrChecksum[256] = { 0 };
+ unsigned char g_usCalculateChecksum = 0x00;
+
+ //09/11/07 NN Type cast mismatch variables
+ usLastBitIndex = (unsigned short)(a_usiDataSize - 1);
+
+ /****************************************************************************
+ *
+ * If mask is not all zeros, then set the display flag to 0x00, otherwise
+ * it shall be set to 0x01 to indicate that data read from the device shall
+ * be displayed. If VME_DEBUG is defined, always display data.
+ *
+ *****************************************************************************/
+
+ for (usDataSizeIndex = 0; usDataSizeIndex < (a_usiDataSize + 7) / 8; usDataSizeIndex++) {
+
+ if (g_usDataType & MASK_DATA) {
+ if (g_pucOutMaskData[usDataSizeIndex] != 0x00) {
+ ucDisplayFlag = 0x00;
+ break;
+ }
+ } else if (g_usDataType & CMASK_DATA) {
+ g_usCalculateChecksum = 0x01;
+ ucDisplayFlag = 0x00;
+ break;
+ } else {
+ ucDisplayFlag = 0x00;
+ break;
+ }
+ }
+
+ /****************************************************************************
+ *
+ * Begin shifting data in and out of the device.
+ *
+ *****************************************************************************/
+ for (usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++) {
+ if (cByteIndex == 0) {
+
+ /***************************************************************
+ *
+ * Grab byte from TDO buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & TDO_DATA) {
+ cDataByte = g_pucOutData[usBufferIndex];
+ }
+
+ /***************************************************************
+ *
+ * Grab byte from MASK buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & MASK_DATA) {
+ cMaskByte = g_pucOutMaskData[usBufferIndex];
+ } else {
+ cMaskByte = 0xFF;
+ }
+
+ /***************************************************************
+ *
+ * Grab byte from CMASK buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & CMASK_DATA) {
+ cMaskByte = 0x00;
+ g_usCalculateChecksum = 0x01;
+ }
+
+ /***************************************************************
+ *
+ * Grab byte from TDI buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & TDI_DATA) {
+ cInDataByte = g_pucInData[usBufferIndex];
+ }
+
+ usBufferIndex++;
+ }
+
+ cCurBit = readPort();
+
+ if (ucDisplayFlag) {
+ ucDisplayByte <<= 1;
+ ucDisplayByte |= cCurBit;
+ }
+
+ /****************************************************************************
+ *
+ * Check if data read from port matches with expected TDO.
+ *
+ *****************************************************************************/
+
+ if (g_usDataType & TDO_DATA) {
+ //08/28/08 NN Added Calculate checksum support.
+ if (g_usCalculateChecksum) {
+ if (cCurBit == 0x01)
+ g_usChecksum += (1 << (g_uiChecksumIndex % 8));
+ g_uiChecksumIndex++;
+ } else {
+ if ((((cMaskByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) {
+ if (cCurBit != (unsigned char)(((cDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) {
+ usErrorCount++;
+ }
+ }
+ }
+ }
+
+ /****************************************************************************
+ *
+ * Write TDI data to the port.
+ *
+ *****************************************************************************/
+
+ writePort(JTAG_TDI, (unsigned char)(((cInDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00));
+
+ if (usDataSizeIndex < usLastBitIndex) {
+
+ /****************************************************************************
+ *
+ * Clock data out from the data shift register.
+ *
+ *****************************************************************************/
+
+ sclock();
+ } else if (g_usFlowControl & CASCADE) {
+
+ /****************************************************************************
+ *
+ * Clock in last bit for the first N - 1 cascaded frames.
+ *
+ *****************************************************************************/
+
+ sclock();
+ }
+
+ /***************************************************************
+ *
+ * Increment the byte index. If it exceeds 7, then reset it back
+ * to zero.
+ *
+ ***************************************************************/
+
+ cByteIndex++;
+ if (cByteIndex >= 8) {
+ if (ucDisplayFlag) {
+
+ /***************************************************************
+ *
+ * Store displayed data in the TDO buffer. By reusing the TDO
+ * buffer to store displayed data, there is no need to allocate
+ * a buffer simply to hold display data. This will not cause any
+ * false verification errors because the true TDO byte has already
+ * been consumed.
+ *
+ ***************************************************************/
+
+ g_pucOutData[usBufferIndex - 1] = ucDisplayByte;
+ ucDisplayByte = 0;
+ }
+
+ cByteIndex = 0;
+ }
+ //09/12/07 Nguyen changed to display the 1 bit expected data
+ else if (a_usiDataSize == 1) {
+ if (ucDisplayFlag) {
+
+ /***************************************************************
+ *
+ * Store displayed data in the TDO buffer. By reusing the TDO
+ * buffer to store displayed data, there is no need to allocate
+ * a buffer simply to hold display data. This will not cause any
+ * false verification errors because the true TDO byte has already
+ * been consumed.
+ *
+ ***************************************************************/
+
+ /****************************************************************************
+ *
+ * Flip ucDisplayByte and store it in cDataByte.
+ *
+ *****************************************************************************/
+ cDataByte = 0x00;
+ for (usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++) {
+ cDataByte <<= 1;
+ if (ucDisplayByte & 0x01) {
+ cDataByte |= 0x01;
+ }
+ ucDisplayByte >>= 1;
+ }
+ g_pucOutData[0] = cDataByte;
+ ucDisplayByte = 0;
+ }
+
+ cByteIndex = 0;
+ }
+ }
+ if (ucDisplayFlag) {
+
+ /****************************************************************************
+ *
+ * Display data read from the device.
+ *
+ *****************************************************************************/
+
+#ifdef VME_DEBUG
+ printf("RECIEVED TDO (");
+#else
+ vme_out_string("Display Data: 0x");
+#endif //VME_DEBUG
+
+ //09/11/07 NN Type cast mismatch variables
+ for (usDataSizeIndex = (unsigned short)((a_usiDataSize + 7) / 8); usDataSizeIndex > 0; usDataSizeIndex--) {
+ cMaskByte = g_pucOutData[usDataSizeIndex - 1];
+ cDataByte = 0x00;
+
+ /****************************************************************************
+ *
+ * Flip cMaskByte and store it in cDataByte.
+ *
+ *****************************************************************************/
+
+ for (usBufferIndex = 0; usBufferIndex < 8; usBufferIndex++) {
+ cDataByte <<= 1;
+ if (cMaskByte & 0x01) {
+ cDataByte |= 0x01;
+ }
+ cMaskByte >>= 1;
+ }
+#ifdef VME_DEBUG
+ printf("%.2X", cDataByte);
+ if ((((a_usiDataSize + 7) / 8) - usDataSizeIndex) % 40 == 39) {
+ printf("\n\t\t");
+ }
+#else
+ vme_out_hex(cDataByte);
+#endif //VME_DEBUG
+ }
+
+#ifdef VME_DEBUG
+ printf(")\n\n");
+#else
+ vme_out_string("\n\n");
+#endif //VME_DEBUG
+ //09/02/08 Nguyen changed to display the data Checksum
+ vme_out_string("g_usChecksum:");
+ sprintf(StrChecksum, "%.4X\n\n", (unsigned int)g_usChecksum);
+ vme_out_string(StrChecksum);
+ vme_out_string("\n\n");
+ if (g_usChecksum != 0) {
+ g_usChecksum &= 0xFFFF;
+ sprintf(StrChecksum, "Data Checksum: %.4X\n\n", (unsigned int)g_usChecksum);
+ vme_out_string(StrChecksum);
+ g_usChecksum = 0;
+ }
+ }
+
+ if (usErrorCount > 0) {
+
+ if (g_usFlowControl & VERIFYUES) {
+ vme_out_string("USERCODE verification failed. Continue programming......\n\n");
+ g_usFlowControl &= ~(VERIFYUES);
+ return 0;
+ } else {
+
+#ifdef VME_DEBUG
+ printf("TOTAL ERRORS: %d\n", usErrorCount);
+#endif //VME_DEBUG
+
+ return VME_VERIFICATION_FAILURE;
+ }
+ } else {
+ if (g_usFlowControl & VERIFYUES) {
+ vme_out_string("USERCODE verification passed. Programming aborted. \n\n");
+ g_usFlowControl &= ~(VERIFYUES);
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+}
+
+/***************************************************************
+*
+* ispVMReadandSave
+*
+* Support dynamic I/O.
+*
+***************************************************************/
+
+signed char ispVMReadandSave(unsigned short int a_usiDataSize)
+{
+ //09/11/07 NN added local variables initialization
+ unsigned short int usDataSizeIndex = 0;
+ unsigned short int usLastBitIndex = 0;
+ unsigned short int usBufferIndex = 0;
+ unsigned short int usOutBitIndex = 0;
+ unsigned short int usLVDSIndex = 0;
+ unsigned char cDataByte = 0;
+ unsigned char cDMASKByte = 0;
+ unsigned char cInDataByte = 0;
+ unsigned char cCurBit = 0;
+ unsigned char cByteIndex = 0;
+ signed char cLVDSByteIndex = 0;
+
+ //09/11/07 NN Type cast mismatch variables
+ usLastBitIndex = (unsigned short)(a_usiDataSize - 1);
+
+ /***************************************************************
+ *
+ * Iterate through the data bits.
+ *
+ ***************************************************************/
+
+ for (usDataSizeIndex = 0; usDataSizeIndex < a_usiDataSize; usDataSizeIndex++) {
+ if (cByteIndex == 0) {
+
+ /***************************************************************
+ *
+ * Grab byte from DMASK buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & DMASK_DATA) {
+ cDMASKByte = g_pucOutDMaskData[usBufferIndex];
+ } else {
+ cDMASKByte = 0x00;
+ }
+
+ /***************************************************************
+ *
+ * Grab byte from TDI buffer.
+ *
+ ***************************************************************/
+
+ if (g_usDataType & TDI_DATA) {
+ cInDataByte = g_pucInData[usBufferIndex];
+ }
+
+ usBufferIndex++;
+ }
+
+ cCurBit = readPort();
+ cDataByte = (unsigned char)(((cInDataByte << cByteIndex) & 0x80) ? 0x01 : 0x00);
+
+ /***************************************************************
+ *
+ * Initialize the byte to be zero.
+ *
+ ***************************************************************/
+
+ if (usOutBitIndex % 8 == 0) {
+ g_pucOutData[usOutBitIndex / 8] = 0x00;
+ }
+
+ /***************************************************************
+ *
+ * Use TDI, DMASK, and device TDO to create new TDI (actually
+ * stored in g_pucOutData).
+ *
+ ***************************************************************/
+
+ if ((((cDMASKByte << cByteIndex) & 0x80) ? 0x01 : 0x00)) {
+
+ if (g_pLVDSList) {
+ for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) {
+ if (g_pLVDSList[usLVDSIndex].usNegativeIndex == usDataSizeIndex) {
+ g_pLVDSList[usLVDSIndex].ucUpdate = 0x01;
+ break;
+ }
+ }
+ }
+
+ /***************************************************************
+ *
+ * DMASK bit is 1, use TDI.
+ *
+ ***************************************************************/
+
+ g_pucOutData[usOutBitIndex / 8] |= (unsigned char)(((cDataByte & 0x1) ? 0x01 : 0x00) << (7 - usOutBitIndex % 8));
+ } else {
+
+ /***************************************************************
+ *
+ * DMASK bit is 0, use device TDO.
+ *
+ ***************************************************************/
+
+ g_pucOutData[usOutBitIndex / 8] |= (unsigned char)(((cCurBit & 0x1) ? 0x01 : 0x00) << (7 - usOutBitIndex % 8));
+ }
+
+ /***************************************************************
+ *
+ * Shift in TDI in order to get TDO out.
+ *
+ ***************************************************************/
+
+ usOutBitIndex++;
+ writePort(JTAG_TDI, cDataByte);
+ if (usDataSizeIndex < usLastBitIndex) {
+ sclock();
+ }
+
+ /***************************************************************
+ *
+ * Increment the byte index. If it exceeds 7, then reset it back
+ * to zero.
+ *
+ ***************************************************************/
+
+ cByteIndex++;
+ if (cByteIndex >= 8) {
+ cByteIndex = 0;
+ }
+ }
+
+ /***************************************************************
+ *
+ * If g_pLVDSList exists and pairs need updating, then update
+ * the negative-pair to receive the flipped positive-pair value.
+ *
+ ***************************************************************/
+
+ if (g_pLVDSList) {
+ for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) {
+ if (g_pLVDSList[usLVDSIndex].ucUpdate) {
+
+ /***************************************************************
+ *
+ * Read the positive value and flip it.
+ *
+ ***************************************************************/
+
+ cDataByte = (unsigned char)(((g_pucOutData[g_pLVDSList[usLVDSIndex].usPositiveIndex / 8] << (g_pLVDSList[usLVDSIndex].usPositiveIndex % 8)) & 0x80) ? 0x01 : 0x00);
+ //09/11/07 NN Type cast mismatch variables
+ cDataByte = (unsigned char)(!cDataByte);
+
+ /***************************************************************
+ *
+ * Get the byte that needs modification.
+ *
+ ***************************************************************/
+
+ cInDataByte = g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8];
+
+ if (cDataByte) {
+
+ /***************************************************************
+ *
+ * Copy over the current byte and set the negative bit to 1.
+ *
+ ***************************************************************/
+
+ cDataByte = 0x00;
+ for (cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex--) {
+ cDataByte <<= 1;
+ if (7 - (g_pLVDSList[usLVDSIndex].usNegativeIndex % 8) == cLVDSByteIndex) {
+
+ /***************************************************************
+ *
+ * Set negative bit to 1.
+ *
+ ***************************************************************/
+
+ cDataByte |= 0x01;
+ } else if (cInDataByte & 0x80) {
+ cDataByte |= 0x01;
+ }
+
+ cInDataByte <<= 1;
+ }
+
+ /***************************************************************
+ *
+ * Store the modified byte.
+ *
+ ***************************************************************/
+
+ g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8] = cDataByte;
+ } else {
+
+ /***************************************************************
+ *
+ * Copy over the current byte and set the negative bit to 0.
+ *
+ ***************************************************************/
+
+ cDataByte = 0x00;
+ for (cLVDSByteIndex = 7; cLVDSByteIndex >= 0; cLVDSByteIndex--) {
+ cDataByte <<= 1;
+ if (7 - (g_pLVDSList[usLVDSIndex].usNegativeIndex % 8) == cLVDSByteIndex) {
+
+ /***************************************************************
+ *
+ * Set negative bit to 0.
+ *
+ ***************************************************************/
+
+ cDataByte |= 0x00;
+ } else if (cInDataByte & 0x80) {
+ cDataByte |= 0x01;
+ }
+
+ cInDataByte <<= 1;
+ }
+
+ /***************************************************************
+ *
+ * Store the modified byte.
+ *
+ ***************************************************************/
+
+ g_pucOutData[g_pLVDSList[usLVDSIndex].usNegativeIndex / 8] = cDataByte;
+ }
+
+ break;
+ }
+ }
+ }
+
+ return (0);
+}
+
+signed char ispVMProcessLVDS(unsigned short a_usLVDSCount)
+{
+ unsigned short usLVDSIndex = 0;
+
+ /***************************************************************
+ *
+ * Allocate memory to hold LVDS pairs.
+ *
+ ***************************************************************/
+
+ ispVMMemManager(LVDS, a_usLVDSCount);
+ g_usLVDSPairCount = a_usLVDSCount;
+
+#ifdef VME_DEBUG
+ printf("LVDS %d (", a_usLVDSCount);
+#endif //VME_DEBUG
+
+ /***************************************************************
+ *
+ * Iterate through each given LVDS pair.
+ *
+ ***************************************************************/
+
+ for (usLVDSIndex = 0; usLVDSIndex < g_usLVDSPairCount; usLVDSIndex++) {
+
+ /***************************************************************
+ *
+ * Assign the positive and negative indices of the LVDS pair.
+ *
+ ***************************************************************/
+
+ //09/11/07 NN Type cast mismatch variables
+ g_pLVDSList[usLVDSIndex].usPositiveIndex = (unsigned short)ispVMDataSize();
+ //09/11/07 NN Type cast mismatch variables
+ g_pLVDSList[usLVDSIndex].usNegativeIndex = (unsigned short)ispVMDataSize();
+
+#ifdef VME_DEBUG
+ if (usLVDSIndex < g_usLVDSPairCount - 1) {
+ printf("%d:%d, ", g_pLVDSList[usLVDSIndex].usPositiveIndex, g_pLVDSList[usLVDSIndex].usNegativeIndex);
+ } else {
+ printf("%d:%d", g_pLVDSList[usLVDSIndex].usPositiveIndex, g_pLVDSList[usLVDSIndex].usNegativeIndex);
+ }
+#endif //VME_DEBUG
+
+ }
+
+#ifdef VME_DEBUG
+ printf(") -- %d;\n", a_usLVDSCount);
+#endif //VME_DEBUG
+
+ return (0);
+}
+
+/***************************************************************
+*
+* ivm_core_reinit
+*
+* Reinit ivm_core variables.
+*
+***************************************************************/
+void ivm_core_reinit()
+{
+ g_usFlowControl = 0x0000;
+ g_usDataType = 0x0000;
+
+ g_ucEndDR = DRPAUSE;
+ g_ucEndIR = IRPAUSE;
+
+ g_usHeadDR = 0;
+ g_usHeadIR = 0;
+ g_usTailDR = 0;
+ g_usTailIR = 0;
+
+ g_usiDataSize = 0;
+
+ g_iFrequency = 1000;
+
+ g_usMaxSize = 0;
+
+ g_usShiftValue = 0;
+
+ g_usRepeatLoops = 0;
+
+ g_cVendor = LATTICE;
+
+ g_usCalculatedCRC = 0;
+
+ g_usChecksum = 0;
+ g_uiChecksumIndex = 0;
+
+ g_cCurrentJTAGState = 0;
+
+ g_pucHeapMemory = NULL;
+ g_iHeapCounter = 0;
+ g_iHEAPSize = 0;
+
+ g_usIntelDataIndex = 0;
+ g_usIntelBufferSize = 0;
+
+ g_usTDOSize = 0;
+ g_usMASKSize = 0;
+ g_usTDISize = 0;
+ g_usDMASKSize = 0;
+ g_usLCOUNTSize = 0;
+ g_usHDRSize = 0;
+ g_usTDRSize = 0;
+ g_usHIRSize = 0;
+ g_usTIRSize = 0;
+ g_usHeapSize = 0;
+
+ g_pucOutMaskData = NULL;
+ g_pucInData = NULL;
+ g_pucOutData = NULL;
+ g_pucHIRData = NULL;
+ g_pucTIRData = NULL;
+ g_pucHDRData = NULL;
+ g_pucTDRData = NULL;
+ g_pucIntelBuffer = NULL;
+ g_pucOutDMaskData = NULL;
+
+ g_pLVDSList = NULL;
+ g_usLVDSPairCount = 0;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_isc/firmware_upgrade_isc.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_isc/firmware_upgrade_isc.c
new file mode 100644
index 0000000000..c252dfde7c
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_isc/firmware_upgrade_isc.c
@@ -0,0 +1,68 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+/*
+ * 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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.c
new file mode 100644
index 0000000000..0a7659f0e4
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.c
@@ -0,0 +1,446 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.h
new file mode 100644
index 0000000000..06e36b3149
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/firmware_upgrade_mtd.h
@@ -0,0 +1,32 @@
+#ifndef __FIRMWARE_UPGRADE_MTD_H__
+#define __FIRMWARE_UPGRADE_MTD_H__
+
+#include
+
+#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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/mtd-abi.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/mtd-abi.h
new file mode 100644
index 0000000000..f326d23e73
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_mtd/mtd-abi.h
@@ -0,0 +1,259 @@
+
+#ifndef __MTD_ABI_H__
+#define __MTD_ABI_H__
+
+#include
+
+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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.c
new file mode 100644
index 0000000000..10a429d93b
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.c
@@ -0,0 +1,285 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#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;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.h
new file mode 100644
index 0000000000..b69080ea64
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/firmware_upgrade_sysfs.h
@@ -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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.c b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.c
new file mode 100644
index 0000000000..7db3c1b7b6
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.c
@@ -0,0 +1,1181 @@
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "fw_upg_spi_logic_dev.h"
+
+#define be32_to_cpus(p) __be32_to_cpus(p)
+#define le32_to_cpus(p) __le32_to_cpus(p)
+#define cpu_to_be32s(p) __cpu_to_be32s(p)
+#define cpu_to_le32s(p) __cpu_to_le32s(p)
+
+static void firmware_upgrade_printf_reg(uint8_t *buf, int buf_len, uint32_t offset_addr)
+{
+ int i, j, tmp;
+
+ j = offset_addr % 16;
+ tmp = j;
+ offset_addr -= j;
+ printf("\n ");
+
+ for (i = 0; i < 16; i++) {
+ printf("%2x ", i);
+ }
+
+ for (i = 0; i < buf_len + j; i++) {
+ if ((i % 16) == 0) {
+ printf("\n0x%08x ", offset_addr);
+ offset_addr = offset_addr + 16;
+ }
+ if (tmp) {
+ printf(" ");
+ tmp--;
+ } else {
+ printf("%02x ", buf[i-j]);
+ }
+ }
+
+ printf("\n");
+ return;
+}
+
+static int firmware_upgrade_get_spi_logic_info(int fd, firmware_spi_logic_upg_t *current_upg_priv)
+{
+ int ret;
+ firmware_spi_logic_info_t syfs_info;
+
+ if (fd < 0) {
+ dbg_print(is_debug_on, "Error: get spi logic info fd %d.\n", fd);
+ return fd;
+ }
+
+ ret = 0;
+ ret = ioctl(fd, FIRMWARE_SYSFS_SPI_INFO, &syfs_info);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Failed to get upg flash dev info, ret=%d\n", ret);
+ return -FW_SPI_FLASH_GET_INFO_ERR;
+ }
+
+ current_upg_priv->flash_base = syfs_info.flash_base;
+ current_upg_priv->ctrl_base = syfs_info.ctrl_base;
+ memcpy(current_upg_priv->dev_path, syfs_info.logic_dev_name, FIRMWARE_LOGIC_DEV_NAME_LEN - 1);
+ current_upg_priv->status_reg = syfs_info.ctrl_base + FPGA_UPG_STATUS_REG;
+ current_upg_priv->spi_ctrl_reg = syfs_info.ctrl_base + FPGA_UPG_SPI_CTRL_REG;
+ current_upg_priv->wr_flash_status_reg = syfs_info.ctrl_base + FPGA_UPG_WR_FLASH_STATUS_REG;
+ current_upg_priv->rd_flash_status_reg = syfs_info.ctrl_base + FPGA_UPG_RD_FLASH_STATUS_REG;
+ current_upg_priv->instruction_reg = syfs_info.ctrl_base + FPGA_UPG_INSTRUCTION_REG;
+ current_upg_priv->addr_reg = syfs_info.ctrl_base + FPGA_UPG_ADDR_REG;
+ current_upg_priv->length_reg = syfs_info.ctrl_base + FPGA_UPG_LENGTH_REG;
+ current_upg_priv->device_id_reg = syfs_info.ctrl_base + FPGA_UPG_DEVICE_ID_REG;
+ current_upg_priv->drop_reg_num_reg = syfs_info.ctrl_base + FPGA_UPG_DROP_REQ_NUM_REG;
+ current_upg_priv->test_base = syfs_info.test_base;
+ current_upg_priv->test_size = syfs_info.test_size;
+
+ return 0;
+}
+
+static int firmware_upgrade_spi_logic_init(int fd)
+{
+ int ret;
+
+ ret = 0;
+ ret = ioctl(fd, FIRMWARE_SYSFS_INIT, NULL);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Failed to init spi logic, ret=%d\n", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int firmware_upgrade_spi_logic_finish(int fd)
+{
+ int ret;
+
+ if (fd < 0) {
+ dbg_print(is_debug_on, "Error: get spi logic info fd %d.\n", fd);
+ return -1;
+ }
+
+ ret = 0;
+ ret = ioctl(fd, FIRMWARE_SYSFS_FINISH, NULL);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Failed to release spi logic, ret=%d\n", ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * firmware_fpga_file_read -
+ * function:Provide FPGA read-register interface (address must be 4-byte aligned)
+ * @dev_name: Device file descriptor
+ * @offset: device offset
+ * @buf: Read Data Buffer
+ * @rd_len: Read Data Length
+ * return: 0--success; other--fail
+ */
+int firmware_fpga_file_read(char *dev_name, uint32_t offset, uint8_t *buf, uint32_t rd_len)
+{
+ int ret, fd;
+
+ if ((dev_name == NULL) || (buf == NULL)) {
+ dbg_print(is_debug_on, "upg_priv or read buf is null.\n");
+ return -1;
+ }
+
+ if ((fd = open(dev_name, O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
+ dbg_print(is_debug_on, "Error: Could not open file %s. Errno=%d\n", dev_name, errno);
+ return -1;
+ }
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "read llseek failed, errno: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ ret = read(fd, buf, rd_len);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "read failed, err: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ return 0;
+}
+
+static int firmware_fpga_read_word(char *dev_name, uint32_t addr, uint32_t *val)
+{
+ int ret;
+ uint32_t retry;
+
+ if (sizeof(int) < FIRMWARE_FPGA_WORD_LEN) {
+ dbg_print(is_debug_on, "Error:dfd_fpga_read_word buf len %ld support len %d.\n",
+ sizeof(int), FIRMWARE_FPGA_WORD_LEN);
+ return -1;
+ }
+
+ retry = 0;
+ *val = 0;
+ while(retry < FIRMWARE_FPGA_UPG_RETRY_CNT) {
+ ret = firmware_fpga_file_read(dev_name, addr, (uint8_t *)val, FIRMWARE_FPGA_WORD_LEN);
+ if (ret) {
+ retry++;
+ dbg_print(is_debug_on, "firmware_fpga_file_read addr 0x%x retry %u failed ret %d.\n",
+ addr, retry, ret);
+ continue;
+ } else {
+ le32_to_cpus(val);
+ return 0;
+ }
+ }
+
+ dbg_print(is_debug_on, "dfd_fpga_read_word addr 0x%x retry %u failed ret %d.\n", addr, retry, ret);
+ return -1;
+}
+
+static int firmware_fpga_read_buf(char *dev_name, uint32_t addr, uint8_t *buf, uint32_t rd_len)
+{
+ int ret;
+ uint32_t retry;
+
+ retry = 0;
+ while(retry < FIRMWARE_FPGA_UPG_RETRY_CNT) {
+ ret = firmware_fpga_file_read(dev_name, addr, buf, rd_len);
+ if (ret) {
+ retry++;
+ dbg_print(is_debug_on, "firmware_fpga_file_read addr 0x%x rd_len %u i %d failed ret %d.\n",
+ addr, rd_len, retry, ret);
+ continue;
+ } else {
+ return 0;
+ }
+ }
+
+ dbg_print(is_debug_on, "firmware_fpga_file_read addr 0x%x rd_len %u retry %u failed ret %d.\n",
+ addr, rd_len, retry, ret);
+ return -1;
+}
+
+/**
+ * firmware_fpga_file_write -
+ * function:Provide FPGA write-register interface (address must be 4-byte aligned)
+ * @dev_name: Device file descriptor
+ * @offset: device offset
+ * @buf: Write Data Buffer
+ * @wr_len: Write Data Length
+ * return: 0--success; other--fail
+ */
+int firmware_fpga_file_write(char *dev_name, uint32_t offset, uint8_t *buf, uint32_t wr_len)
+{
+ int ret, fd;
+
+ if ((dev_name == NULL) || (buf == NULL)) {
+ dbg_print(is_debug_on, "dev_name or write buf is null.\n");
+ return -1;
+ }
+
+ if ((fd = open(dev_name, O_RDWR, S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
+ dbg_print(is_debug_on, "Error: Could not open file %s. Errno=%d\n", dev_name, errno);
+ return -1;
+ }
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "write llseek failed, err: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ ret = write(fd, buf, wr_len);
+ if (ret < 0 ) {
+ dbg_print(is_debug_on, "write failed, err: %s\n", strerror(errno));
+ close(fd);
+ return -1;
+ }
+
+ close(fd);
+ return 0;
+}
+
+static int firmware_fpga_write_word(char *dev_name, uint32_t addr, uint32_t val)
+{
+ int ret;
+ uint32_t retry, tmp;
+
+ retry = 0;
+ tmp = val;
+ cpu_to_le32s(&tmp);
+ while(retry < FIRMWARE_FPGA_UPG_RETRY_CNT) {
+ ret = firmware_fpga_file_write(dev_name, addr, (uint8_t *)&tmp, FIRMWARE_FPGA_WORD_LEN);
+ if (ret) {
+ retry++;
+ dbg_print(is_debug_on, "firmware_fpga_file_write addr 0x%x val 0x%x retry %u failed ret %d.\n",
+ addr, val, retry, ret);
+ continue;
+ } else {
+ return 0;
+ }
+ }
+
+ dbg_print(is_debug_on, "firmware_fpga_file_write addr 0x%x val 0x%x retry %u failed ret %d.\n",
+ addr, val, retry, ret);
+ return -1;
+}
+
+static int firmware_fpga_write_buf(char *dev_name, uint32_t addr, uint8_t *buf, uint32_t wr_len)
+{
+ int ret;
+ uint32_t retry;
+
+ retry = 0;
+ while(retry < FIRMWARE_FPGA_UPG_RETRY_CNT) {
+ ret = firmware_fpga_file_write(dev_name, addr, buf, wr_len);
+ if (ret) {
+ retry++;
+ dbg_print(is_debug_on, "firmware_fpga_file_write addr 0x%x wr_len 0x%x retry %u failed ret %d.\n",
+ addr, wr_len, retry, ret);
+ continue;
+ } else {
+ return 0;
+ }
+ }
+
+ dbg_print(is_debug_on, "dfd_fpga_buf_write addr 0x%x wr_len 0x%x retry %u failed ret %d.\n",
+ addr, wr_len, retry, ret);
+
+ return -1;
+}
+
+/* Whether the SPI port is idle, 0--idle, 1--busy */
+static int firmware_fpga_get_status(firmware_spi_logic_upg_t *upg_priv, char *status)
+{
+ int ret;
+ uint32_t addr, val;
+
+ addr = upg_priv->status_reg;
+ ret = firmware_fpga_read_word(upg_priv->dev_path, addr, &val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_get_status addr 0x%x failed ret %d.\n", addr, ret);
+ return -1;
+ }
+
+ *status = val & FPGA_UPG_STATUS_MASK;
+
+ return 0;
+}
+
+/* Wait for the SPI port to become free again */
+static int firmware_fpga_wait_ready(firmware_spi_logic_upg_t *upg_priv)
+{
+ int timeout;
+ char status;
+ int ret;
+
+ timeout = FIRMWARE_UPG_RETRY_TIME_CNT;
+ while (timeout--) {
+ usleep(FIRMWARE_UPG_RETRY_SLEEP_TIME);
+ ret = firmware_fpga_get_status(upg_priv, &status);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_get_status failed ret %d.\n", ret);
+ continue;
+ }
+
+ /* Determine if it's idle */
+ if (!status) {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+/* Configure access */
+static int firmware_fpga_set_access(firmware_spi_logic_upg_t *upg_priv, uint32_t cmd)
+{
+ int ret;
+ uint32_t addr, val;
+
+ addr = upg_priv->instruction_reg;
+ val = cmd;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret);
+ return -1;
+ }
+
+ addr = upg_priv->spi_ctrl_reg;
+ val = FPGA_UPG_ACCESS_ENABLE;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret);
+ return -1;
+ }
+
+ /* Wait for the SPI port on the FPGA to become free again*/
+ ret = firmware_fpga_wait_ready(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_wait_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_BUSY;
+ }
+
+ return 0;
+}
+
+/* Get SPI STATUS register */
+static int firmware_fpga_get_spi_status(firmware_spi_logic_upg_t *upg_priv, char *status)
+{
+ int ret;
+ uint32_t val, addr, cmd;
+
+ cmd = FPGA_UPG_INSTRUTION_RDSR;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_access cmd 0x%x failed ret %d.\n", cmd, ret);
+ return -1;
+ }
+
+ addr = upg_priv->rd_flash_status_reg;
+ ret = firmware_fpga_read_word(upg_priv->dev_path, addr, &val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_read_word addr 0x%x failed ret %d.\n", addr, ret);
+ return -1;
+ }
+
+ *status = val & FPGA_UPG_SPI_STATUS_MASK;
+
+ return 0;
+}
+
+/* Wait for the SPI chip operation to complete */
+static int firmware_fpga_wait_spi_ready(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t timeout, uint32_t usleep_time)
+{
+ char status;
+ int ret;
+
+ while (timeout--) {
+ usleep(usleep_time);
+ ret = firmware_fpga_get_spi_status(upg_priv, &status);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_get_spi_status failed ret %d.\n", ret);
+ continue;
+ }
+ /* Determine if it's idle */
+ if (!status) {
+ return 0;
+ }
+ }
+
+ return -FW_SPI_FLASH_SPI_BUSY;
+}
+
+/* Configure FPGA upgrade write enable */
+static int firmware_fpga_set_wr_enable(firmware_spi_logic_upg_t *upg_priv)
+{
+ int ret;
+ uint32_t cmd;
+
+ cmd = FPGA_UPG_INSTRUTION_WREN;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_access cmd %d failed ret %d.\n", cmd, ret);
+ return -1;
+ }
+
+ return 0;
+}
+
+#if 0
+/* erase all flash */
+static int firmware_fpga_upg_set_erase_all(firmware_spi_logic_upg_t *upg_priv)
+{
+ int ret;
+ int cmd;
+
+ /* Wait for the SPI port on the FPGA to become free */
+ ret = firmware_fpga_wait_ready(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_wait_ready failed ret %d.\n", ret);
+ return -1;
+ }
+
+ /* Configure FPGA upgrade write enable */
+ ret = firmware_fpga_set_wr_enable(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_wr_enable failed ret %d.\n", ret);
+ return -1;
+ }
+
+ cmd = FPGA_UPG_INSTRUTION_BE;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_access cmd %d failed ret %d.\n", cmd, ret);
+ return -1;
+ }
+
+ /* Hardware requirements, delay of 1s */
+ sleep(1);
+
+ /* Wait for the SPI chip operation to complete, 1s check status once, max delay 300s */
+ ret = firmware_fpga_wait_spi_ready(upg_priv, 300, (1 * 1000 * 1000));
+ if (ret) {
+ dbg_print(is_debug_on, "dfd_fpga_wait_spi_ready failed ret %d.\n", ret);
+ return -1;
+ }
+
+ dbg_print(is_debug_on, "Success.\n");
+ return 0;
+}
+#endif
+
+/* Erase sectors (256 pages, 64K total) */
+static int firmware_fpga_erase_sector(firmware_spi_logic_upg_t *upg_priv, uint32_t spi_addr)
+{
+ int ret;
+ uint32_t val, addr, cmd;
+
+ /* Wait for the SPI port on the FPGA to become free again */
+ ret = firmware_fpga_wait_ready(upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "firmware_fpga_wait_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_BUSY;
+ }
+
+ /* Enable write */
+ ret = firmware_fpga_set_wr_enable(upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "firmware_fpga_set_wr_enable failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_WR_ENABLE_ERR;
+ }
+
+ /* Write erase address */
+ val = spi_addr;
+ addr = upg_priv->addr_reg;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n", addr, val, ret);
+ return -FW_SPI_FLASH_ERASE_ADDR_ERR;
+ }
+
+ /* Enable sector erasure */
+ cmd = FPGA_UPG_INSTRUTION_SE;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_access cmd %d failed ret %d.\n", cmd, ret);
+ return -FW_SPI_FLASH_ERASE_SECTOR_ERR;
+ }
+
+ /* Hardware requirements, delay of 0.25s */
+ usleep(250 * 1000);
+
+ /* Wait for the SPI chip operation to complete, 1s check status once, max delay 10s */
+ ret = firmware_fpga_wait_spi_ready(upg_priv, FPGA_UPG_WAIT_SPI_RETRY_CNT, (100 * 1000));
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_wait_spi_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_SPI_BUSY;
+ }
+
+ return 0;
+}
+
+#if 0
+int firmware_fpga_erase64_sector(firmware_spi_logic_upg_t *upg_priv, int offset)
+{
+ int ret;
+ ret = -1;
+
+ if ((offset % FIRMWARE_SPI_LOGIC_SECTOR_SIZE) == 0) {
+ dbg_print(is_debug_on, "erase 64k area, offset 0x%x.\n", offset);
+ ret = firmware_fpga_erase_sector(upg_priv, offset);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_erase_sector offset 0x%x failed ret %d.\n", offset, ret);
+ return ret;
+ }
+ } else {
+ dbg_print(is_debug_on, "Input para invalid, offset 0x%x.\n", offset);
+ }
+
+ return ret;
+}
+#endif
+
+static int firmware_fpga_upg_program(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t spi_addr, uint8_t *buf, uint32_t len)
+{
+ int ret;
+ uint32_t addr, val, cmd, wr_len;
+
+ /* Write data to the Upgrade Content Register */
+ addr = upg_priv->ctrl_base;
+ wr_len = len;
+ ret = firmware_fpga_write_buf(upg_priv->dev_path, addr, (uint8_t*)buf, wr_len);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_write_buf addr 0x%x wr_len %d failed ret %d.\n",
+ addr, len, ret);
+ return -FW_SPI_FLASH_WR_ERR;
+ }
+
+ /* Write length register, FPGA is fixed 256 lengths */
+ val = FFPGA_UPG_DATA_SIZE;
+ addr = upg_priv->length_reg;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n",
+ addr, val, ret);
+ return -FW_SPI_FLASH_WR_LENGTH_ERR;
+ }
+
+ /* Write address register */
+ val = spi_addr;
+ addr = upg_priv->addr_reg;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n",
+ addr, val, ret);
+ return -FW_SPI_FLASH_WR_ADDR_ERR;
+ }
+
+ /* Start writing upgrade data to SPI */
+ cmd = FPGA_UPG_INSTRUTION_PP;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_set_access cmd %d failed ret %d.\n", cmd, ret);
+ return -FW_SPI_FLASH_SET_ACCESS_ERR;
+ }
+
+ /* min write wait 0.33ms */
+ usleep(330);
+
+ /* Wait for the SPI chip operation to complete, 100us check status once, max delay 10ms */
+ ret = firmware_fpga_wait_spi_ready(upg_priv, FPGA_UPG_WAIT_SPI_RETRY_CNT, (100));
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_wait_spi_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_BUSY;
+ }
+
+ return 0;
+}
+
+/**
+ * firmware_fpga_upg_write
+ * function: write interface provided to the upgrade module
+ * @upg_priv: Device information
+ * @addr: upgrade addr
+ * @buf: Write Data Buffer
+ * @len: Write Data Length
+ * return: 0--success; other--fail
+ */
+static int firmware_fpga_upg_write(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t addr, uint8_t *buf, uint32_t len)
+{
+ int ret;
+
+ /* address must be 256 bytes aligned */
+ if ((upg_priv == NULL) || (buf == NULL) || (addr & 0xff) || (len > 256)) {
+ dbg_print(is_debug_on,"Input para invalid upg_priv %p buf %p addr 0x%x len %u.\n",
+ upg_priv, buf, addr, len);
+ return -FW_SPI_FLASH_PARAM_ERR;
+ }
+
+ /* Wait for the SPI port on the FPGA to become free again*/
+ ret = firmware_fpga_wait_ready(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_wait_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_BUSY;
+ }
+
+ /* Configure write enable */
+ ret = firmware_fpga_set_wr_enable(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on,"firmware_fpga_set_wr_enable failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_WR_ENABLE_ERR;
+ }
+
+ /* Write upgrade data */
+ ret = firmware_fpga_upg_program(upg_priv, addr, buf, len);
+ if (ret) {
+ dbg_print(is_debug_on,"dfd_fpga_upg_program addr 0x%x len %u failed ret %d.\n", addr, len, ret);
+ return -FW_SPI_FLASH_UPG_ERR;
+ }
+
+ return 0;
+}
+
+static int firmware_fpga_fast_read(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t spi_addr, uint8_t *buf, uint32_t len)
+{
+ int ret;
+ uint32_t val, addr, cmd;
+
+ /* Clear register value */
+ addr = upg_priv->ctrl_base;
+ ret = firmware_fpga_write_buf(upg_priv->dev_path, addr, buf, len);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_buf addr 0x%x len %d failed ret %d.\n", addr, len, ret);
+ return -FW_SPI_FLASH_WR_ERR;
+ }
+ /* Write length register */
+ val = FFPGA_UPG_DATA_SIZE;
+ addr = upg_priv->length_reg;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n",
+ addr, val, ret);
+ return -FW_SPI_FLASH_WR_LENGTH_ERR;
+ }
+
+ /* Write address register */
+ val = spi_addr;
+ addr = upg_priv->addr_reg;
+ ret = firmware_fpga_write_word(upg_priv->dev_path, addr, val);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_write_word addr 0x%x val 0x%x failed ret %d.\n",
+ addr, val, ret);
+ return -FW_SPI_FLASH_WR_ADDR_ERR;
+ }
+
+ /* Start reading SPI data */
+ cmd = FPGA_UPG_INSTRUTION_FR;
+ ret = firmware_fpga_set_access(upg_priv, cmd);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_access cmd %d failed ret %d.\n", cmd, ret);
+ return -FW_SPI_FLASH_SET_ACCESS_ERR;
+ }
+
+ /* Read the upgraded content register to the buffer,
+ * FPGA only supports 4 bytes of read and write */
+ addr = upg_priv->ctrl_base;
+ ret = firmware_fpga_read_buf(upg_priv->dev_path, addr, (uint8_t*)buf, len);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_read_buf addr 0x%x len %d failed ret %d.\n", addr, len, ret);
+ return -FW_SPI_FLASH_RD_ERR;
+ }
+
+ return 0;
+}
+
+/**
+ * firmware_fpga_upg_read
+ * function: read interface provided to the upgrade module
+ * @upg_priv: Device information
+ * @addr: upgrade addr
+ * @buf: Read Data Buffer
+ * @len: Read Data Length
+ * return: 0--success; other--fail
+ */
+static int firmware_fpga_upg_read(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t addr, uint8_t *buf, uint32_t len)
+{
+ int ret;
+
+ /* address must be 256 bytes aligned */
+ if ((upg_priv == NULL) || (buf == NULL) || (addr & 0xff) || (len > 256)) {
+ dbg_print(is_debug_on, "Input para invalid upg_priv %p buf %p addr 0x%x len %u.\n",
+ upg_priv, buf, addr, len);
+ return -FW_SPI_FLASH_PARAM_ERR;
+ }
+
+ /* Wait for the SPI port on the FPGA to become free again */
+ ret = firmware_fpga_wait_ready(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_wait_ready failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_BUSY;
+ }
+
+ /* Configure write enable */
+ ret = firmware_fpga_set_wr_enable(upg_priv);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_set_wr_enable failed ret %d.\n", ret);
+ return -FW_SPI_FLASH_WR_ENABLE_ERR;
+ }
+
+ /* Read upgrade data */
+ ret = firmware_fpga_fast_read(upg_priv, addr, buf, len);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_fast_read addr 0x%x len %u failed ret %d.\n", addr, len, ret);
+ return -FW_SPI_FLASH_RD_ERR;
+ }
+
+ return 0;
+
+}
+
+static int firmware_upgreade_fpga_onetime(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t flash_base, uint8_t *buf, uint32_t size)
+{
+ uint32_t offset, len, flash_addr, retry;
+ int ret, res;
+ uint8_t rbuf[FFPGA_UPG_DATA_SIZE];
+
+ offset = 0;
+ while(offset < size) {
+ flash_addr = flash_base + offset;
+ /* Erases a sector */
+ if ((flash_addr % FIRMWARE_SPI_LOGIC_SECTOR_SIZE) == 0) {
+ ret = firmware_fpga_erase_sector(upg_priv, flash_addr);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "firmware_fpga_erase_sector flash_addr 0x%x failed ret %d.\n",
+ flash_addr, ret);
+ goto exit;
+ }
+ }
+
+ if (size > FFPGA_UPG_DATA_SIZE) {
+ len = FFPGA_UPG_DATA_SIZE;
+ } else {
+ len = size;
+ }
+
+ /* first, Write data */
+ ret = firmware_fpga_upg_write(upg_priv, flash_addr, buf + offset, len);
+ if (ret) {
+ dbg_print(is_debug_on, "firmware_fpga_upg_write addr 0x%x len 0x%x failed ret %d.\n",
+ flash_addr, len, ret);
+ ret = -FW_SPI_FLASH_UPG_ERR;
+ goto exit;
+ }
+
+ /* Read back the data and compare the correctness of the data */
+ for (retry = 0; retry < FPGA_UPG_RETRY_TIMES; retry++) { /*retry 3 times*/
+ mem_clear(rbuf, len);
+ ret = firmware_fpga_upg_read(upg_priv, flash_addr, rbuf, len);
+ res = memcmp(rbuf, buf + offset, len);
+ if (ret || res) {
+ usleep(1000);
+ continue;
+ }
+ break;
+ }
+
+ if (ret) {
+ dbg_print(is_debug_on, "firmware fpga read offset 0x%x len 0x%x failed ret %d.\n", flash_addr, len, ret);
+ ret = -FW_SPI_FLASH_RD_ERR;
+ goto exit;
+ }
+
+ if (res) {
+ dbg_print(is_debug_on, "firmware fpga rbuf wbuf not equal, len 0x%x, check failed.\n", len);
+ ret = -FW_SPI_FLASH_DATA_CMP_ERR;
+ goto exit;
+ }
+ offset += len;
+ }
+
+ dbg_print(is_debug_on, "Update success.\n");
+ return FIRMWARE_SUCCESS;
+exit:
+ dbg_print(is_debug_on, "Update failed.\n");
+ return FIRMWARE_FAILED;
+}
+
+static int firmware_upgrade_do_spi_logic(firmware_spi_logic_upg_t *current_upg_priv,
+ unsigned char *buf, uint32_t size)
+{
+ int i, ret;
+ uint32_t retry;
+
+ i = 0;
+ retry = FIRMWARE_SPI_LOGIC_UPG_RETRY_CNT;
+
+ ret = 0;
+ while(i < retry) {
+ ret = firmware_upgreade_fpga_onetime(current_upg_priv, current_upg_priv->flash_base, buf, size);
+ if (ret) {
+ i++;
+ dbg_print(is_debug_on, "firmware_upgreade_fpga_onetime size 0x%x failed ret %d.\n", size, ret);
+ continue;
+ } else {
+ dbg_print(is_debug_on, "firmware_upgreade_fpga_onetime success.\n");
+ return 0;
+ }
+ }
+
+ return ret;
+}
+
+/*
+ * firmware_upgrade_spi_logic_dev
+ * function: FPGA SPI FLASH Firmware upgrade handler function
+ * @fd: param[in] sysfs device descriptor
+ * @buf: param[in] Update data
+ * @size: param[in] Update data size
+ * @info: param[in] Upgrade file information
+ * return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int firmware_upgrade_spi_logic_dev(int fd, uint8_t *buf, uint32_t size, name_info_t *info)
+{
+ int ret;
+ firmware_spi_logic_upg_t current_upg_priv;
+
+ if ((fd < 0) || (buf == NULL) || (info == NULL)) {
+ dbg_print(is_debug_on, "Error:firmware upgrade spi logic dev parameters failed.\n");
+ return FIRMWARE_FAILED;
+ }
+
+ /* Gets the current logical device information */
+ mem_clear(¤t_upg_priv, sizeof(firmware_spi_logic_upg_t));
+ ret = firmware_upgrade_get_spi_logic_info(fd, ¤t_upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_get_spi_logic_info failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ dbg_print(is_debug_on, "current_upg_priv dev_path[%s] flash_base[0x%0x] ctrl_base[0x%0x]\n",
+ current_upg_priv.dev_path, current_upg_priv.flash_base,
+ current_upg_priv.ctrl_base);
+
+ /* Enable upgrade access */
+ ret = firmware_upgrade_spi_logic_init(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_init failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ /* Upgrade logic device */
+ ret = firmware_upgrade_do_spi_logic(¤t_upg_priv, buf, size);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_do_spi_logic failed ret %d.\n", ret);
+ goto fail;
+ }
+
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_SUCCESS;
+fail:
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_FAILED;
+}
+
+int firmware_fpga_upgrade_test(firmware_spi_logic_upg_t *current_upg_priv)
+{
+ int ret, i, j, num;
+ uint8_t *wbuf;
+ uint32_t retry;
+
+ ret = FW_SPI_FLASH_RV_OK;
+ wbuf = (uint8_t *) malloc(current_upg_priv->test_size);
+ if (wbuf == NULL) {
+ dbg_print(is_debug_on, "Error: Failed to malloc memory for test data buf, size=0x%x.\n", current_upg_priv->test_size);
+ ret = -FW_SPI_FLASH_NOT_SUPPORT_TEST;
+ goto exit;
+ }
+ mem_clear(wbuf, current_upg_priv->test_size);
+ /* Get random data */
+ for (j = 0; j < current_upg_priv->test_size; j++) {
+ num = rand() % 256;
+ wbuf[j] = num & 0xff;
+ }
+
+ i = 0;
+ retry = FIRMWARE_SPI_LOGIC_UPG_RETRY_CNT;
+
+ ret = 0;
+ while(i < retry) {
+ ret = firmware_upgreade_fpga_onetime(current_upg_priv, current_upg_priv->test_base, wbuf, current_upg_priv->test_size);
+ if (ret) {
+ i++;
+ dbg_print(is_debug_on, "firmware_upgreade_fpga_onetime test size 0x%x failed ret %d.\n",
+ current_upg_priv->test_size, ret);
+ continue;
+ } else {
+ dbg_print(is_debug_on, "firmware_upgreade_fpga_onetime test success.\n");
+ break;
+ }
+ }
+ free(wbuf);
+exit:
+ return ret;
+}
+
+/*
+ * firmware_upgrade_spi_logic_dev_test
+ * function: FPGA SPI FLASH Firmware upgrade test handler function
+ * @fd: param[in] sysfs device descriptor
+ * @buf: param[in] Update data
+ * @size: param[in] Update data size
+ * @info: param[in] Upgrade file information
+ * return value : success--FIRMWARE_SUCCESS; fail--FIRMWARE_FAILED
+ */
+int firmware_upgrade_spi_logic_dev_test(int fd, name_info_t *info)
+{
+ int ret;
+ firmware_spi_logic_upg_t current_upg_priv;
+
+ if ((fd < 0) || (info == NULL)) {
+ dbg_print(is_debug_on, "Error:firmware upgrade spi logic dev parameters failed.\n");
+ return FIRMWARE_FAILED;
+ }
+
+ /* Gets the current logical device information */
+ mem_clear(¤t_upg_priv, sizeof(firmware_spi_logic_upg_t));
+ ret = firmware_upgrade_get_spi_logic_info(fd, ¤t_upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_get_spi_logic_info failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ dbg_print(is_debug_on, "current_upg_priv dev_path[%s] test_base[0x%0x] test_size[0x%x]\n",
+ current_upg_priv.dev_path, current_upg_priv.test_base, current_upg_priv.test_size);
+ if (current_upg_priv.test_size <= 0) {
+ dbg_print(is_debug_on, "Error: don't support flast test.\n");
+ return FIRMWARE_NOT_SUPPORT;
+ }
+
+ /* Enable upgrade access */
+ ret = firmware_upgrade_spi_logic_init(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_init failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ /* Upgrade logic device */
+ ret = firmware_fpga_upgrade_test(¤t_upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_do_spi_logic failed ret %d.\n", ret);
+ goto fail;
+ }
+
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_SUCCESS;
+fail:
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_FAILED;
+}
+
+static int firmware_upgreade_spi_logic_dump(firmware_spi_logic_upg_t *upg_priv,
+ uint32_t offset, uint8_t *buf, uint32_t size)
+{
+ int ret, i;
+ uint32_t addr, buf_page, retry, cnt, rd_len;
+
+ buf_page = FFPGA_UPG_DATA_SIZE; /* read data by BUF SIZE each time */
+
+ cnt = size / FFPGA_UPG_DATA_SIZE;
+ if (size % FFPGA_UPG_DATA_SIZE) {
+ cnt++;
+ }
+ dbg_print(is_debug_on, "need read number of times:%d.\n", cnt);
+
+ for (i = 0; i < cnt; i++) {
+ addr = offset + i * FFPGA_UPG_DATA_SIZE;
+ if (i == (cnt - 1)) {
+ /* last time read remain size */
+ rd_len = size - buf_page * i;
+ } else {
+ /* each time read buf page size */
+ rd_len = buf_page;
+ }
+
+ for (retry = 0; retry < FPGA_UPG_RETRY_TIMES; retry++) {
+ ret = firmware_fpga_upg_read(upg_priv, addr, buf, rd_len);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "addr:0x%x read %d time failed. ret %d\n", addr, retry, ret);
+ continue;
+ }
+ break;
+ }
+
+ if (ret < 0) {
+ dbg_print(is_debug_on, "finally addr:0x%x read failed ret %d\n", addr, ret);
+ return FIRMWARE_FAILED;
+ }
+
+ buf += rd_len; /* buf pointer offset rd_len */
+ }
+
+ return FIRMWARE_SUCCESS;
+}
+
+static int firmware_fpga_dump_read(int fd, uint32_t offset, uint8_t *buf, uint32_t len)
+{
+ int ret;
+ firmware_spi_logic_upg_t current_upg_priv;
+
+ if ((fd < 0) || (buf == NULL)) {
+ dbg_print(is_debug_on, "Error:firmware upgrade spi logic dev parameters failed.\n");
+ return FIRMWARE_FAILED;
+ }
+
+ /* Gets the current logical device information */
+ mem_clear(¤t_upg_priv, sizeof(firmware_spi_logic_upg_t));
+ ret = firmware_upgrade_get_spi_logic_info(fd, ¤t_upg_priv);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_get_spi_logic_info failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ dbg_print(is_debug_on, "current_upg_priv dev_path[%s] flash_base[0x%0x] ctrl_base[0x%0x]\n",
+ current_upg_priv.dev_path, current_upg_priv.flash_base,
+ current_upg_priv.ctrl_base);
+
+ /* Enable upgrade access */
+ ret = firmware_upgrade_spi_logic_init(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_init failed ret %d.\n", ret);
+ return FIRMWARE_FAILED;
+ }
+
+ /* read logic device */
+ ret = firmware_upgreade_spi_logic_dump(¤t_upg_priv, offset, buf, len);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_do_spi_logic failed ret %d.\n", ret);
+ goto fail;
+ }
+
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_SUCCESS;
+
+fail:
+ /* disable upgrade access */
+ ret = firmware_upgrade_spi_logic_finish(fd);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "Error:firmware_upgrade_spi_logic_finish failed ret %d.\n", ret);
+ }
+
+ return FIRMWARE_FAILED;
+}
+
+int firmware_upgrade_spi_logic_dev_dump(char *dev_name, uint32_t offset,
+ uint32_t len, char *record_file)
+{
+ int ret, dev_fd, file_fd;
+ char save_file[FIRMWARE_LOGIC_DEV_NAME_LEN];
+ uint8_t *buf;
+
+ dev_fd = open(dev_name, O_RDWR);
+ if (dev_fd < 0) {
+ dbg_print(is_debug_on, "Error: Failed to open %s, errno:%d.\n", dev_name, errno);
+ return FIRMWARE_FAILED;
+ }
+
+ dbg_print(is_debug_on, "open dev file %s succeeded.\n", dev_name);
+
+ buf = (uint8_t *) malloc(len);
+ if (buf == NULL) {
+ dbg_print(is_debug_on, "Error: Failed to malloc memory read %s data.\n", dev_name);
+ ret = FIRMWARE_FAILED;
+ goto free_dev_fd;
+ }
+
+ mem_clear(buf, len);
+ ret = firmware_fpga_dump_read(dev_fd, offset, buf, len);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "addr 0x%x read 0x%x failed ret:%d\n", offset, len, ret);
+ goto free_data;
+ }
+
+ dbg_print(is_debug_on, "dump data succeeded. offset:0x%x, len:0x%x\n", offset, len);
+
+ if (strcmp(record_file, "print") != 0) { /* record dump data on 'record_file' */
+ mem_clear(save_file, FIRMWARE_LOGIC_DEV_NAME_LEN);
+ strncpy(save_file, record_file, FIRMWARE_LOGIC_DEV_NAME_LEN - 1);
+ file_fd = open(save_file, O_RDWR|O_CREAT|O_TRUNC, S_IRWXG|S_IRWXU|S_IRWXO);
+ if (file_fd < 0) {
+ dbg_print(is_debug_on, "open file %s fail, errno:%d.\n", save_file, errno);
+ ret = -ENOENT;
+ goto free_data;
+ }
+
+ dbg_print(is_debug_on, "open save file %s succeeded.\n", save_file);
+
+ ret = write(file_fd, buf, len);
+ if (ret < 0) {
+ dbg_print(is_debug_on, "write failed (errno: %d).\n", errno);
+ goto free_file_fd;
+ }
+ dbg_print(is_debug_on, "write save file %s succeeded.\n", save_file);
+ ret = FIRMWARE_SUCCESS;
+ } else { /* print reg on terminal by format */
+ firmware_upgrade_printf_reg((uint8_t*)buf, len, offset);
+ ret = FIRMWARE_SUCCESS;
+ goto free_data;
+ }
+
+free_file_fd:
+ close(file_fd);
+free_data:
+ free(buf);
+free_dev_fd:
+ close(dev_fd);
+
+ return ret;
+}
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.h
new file mode 100644
index 0000000000..32f820161e
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/fw_upg_sysfs/fw_upg_spi_logic_dev.h
@@ -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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/debug.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/debug.h
new file mode 100644
index 0000000000..17dd42c3ef
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/debug.h
@@ -0,0 +1,34 @@
+/*
+ *
+ * debug.h
+ * firmware upgrade debug switch control
+ */
+
+#ifndef __FIRMWARE_UPGRADE_DEBUG_H__
+#define __FIRMWARE_UPGRADE_DEBUG_H__
+#include
+
+#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__ */
diff --git a/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/firmware_app.h b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/firmware_app.h
new file mode 100644
index 0000000000..581b2e969e
--- /dev/null
+++ b/platform/broadcom/sonic-platform-modules-ragile/common/app/firmware_upgrade/firmware_upgrade/include/firmware_app.h
@@ -0,0 +1,172 @@
+#ifndef __FIRMWARE_APP_H__
+#define __FIRMWARE_APP_H__
+
+#include
+#include