forked from APS-Networks/APS-One-touch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrivers.py
156 lines (130 loc) · 4.47 KB
/
drivers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
import subprocess
import tarfile
import zipfile
import common
import constants
from common import execute_cmd, get_env_var, dname, create_symlinks, \
is_ubuntu, get_switch_model_from_settings
installation_files = {
"irq_debug_tgz": "./irq_debug.tgz",
"mv_pipe_config_zip": "./mv_pipe_config.zip"
}
def load_and_verify_kernel_modules():
output = execute_cmd('lsmod')
bf_kdrv = False
bf_kpkt = True
i2c_i801 = True
BF_KDRV = False
BF_KPKT = True
os.system("sudo modprobe -q i2c-i801")
os.system("sudo modprobe -q i2c-dev")
if BF_KDRV:
if 'bf_kdrv' not in output:
load_bf_kdrv()
else:
if 'bf_kpkt' not in output:
load_bf_kpkt()
output = execute_cmd('lsmod')
if 'i2c_i801' not in output and is_ubuntu():
# Ubuntu check is there because i2c_i801 appears only in output of lsmod in Ubuntu
i2c_i801 = False
print('ERROR:i2c_i801 is not loaded.')
if BF_KDRV:
if 'bf_kdrv' not in output:
bf_kdrv = False
print("ERROR:bf_kdrv is not loaded.")
else:
if 'bf_kpkt' not in output:
bf_kpkt = False
print("ERROR:bf_kpkt is not loaded.")
# Load switch specific kernel modules
if get_switch_model_from_settings() == constants.bf2556x_1t:
if BF_KDRV:
return bf_kdrv and i2c_i801 and load_and_verify_kernel_modules_bf2556()
else:
return bf_kpkt and i2c_i801 and load_and_verify_kernel_modules_bf2556()
else:
if BF_KDRV:
return bf_kdrv and i2c_i801 and load_and_verify_kernel_modules_bf6064()
else:
return bf_kpkt and i2c_i801 and load_and_verify_kernel_modules_bf6064()
def load_and_verify_kernel_modules_bf6064():
execute_cmd('sudo i2cset -y 0 0x70 0x20 \
sudo i2cset -y 0 0x32 0xE 0x0 \
sudo i2cset -y 0 0x32 0xF 0x0 \
sudo i2cset -y 0 0x34 0x2 0x0 \
sudo i2cset -y 0 0x34 0x3 0x0 \
sudo i2cset -y 0 0x34 0x4 0x0 \
sudo i2cset -y 0 0x35 0x2 0x0 \
sudo i2cset -y 0 0x35 0x3 0x0 \
sudo i2cset -y 0 0x35 0x4 0x0 \
sudo i2cset -y 0 0x70 0x20 \
sudo i2cset -y 0 0x32 0x14 0xff \
sudo i2cset -y 0 0x32 0x15 0xff \
sudo i2cset -y 0 0x34 0xB 0xff \
sudo i2cset -y 0 0x34 0xC 0xff \
sudo i2cset -y 0 0x34 0xD 0xff \
sudo i2cset -y 0 0x35 0xB 0xff \
sudo i2cset -y 0 0x35 0xC 0xff \
sudo i2cset -y 0 0x35 0xD 0xff')
return True
sde_folder_path = ""
#sde = installation_files["sde"]
def load_and_verify_kernel_modules_bf2556():
output = execute_cmd('lsmod')
irq_debug = True
mv_pipe = True
if 'irq_debug' not in output:
install_irq_debug()
if not os.path.exists("/delta/mv_pipe_config"):
install_mv_pipe()
#Verify that modules are loaded.
output = execute_cmd('lsmod')
if 'irq_debug' not in output:
irq_debug = False
print("ERROR:irq_debug is not loaded.")
if not os.path.exists("/delta/mv_pipe_config"):
mv_pipe = False
print("ERROR:mv_pipe_config not installed.")
return irq_debug and mv_pipe
def install_irq_debug():
print("Installing irq_debug...")
os.chdir(dname)
print("Working dir :{}".format(dname))
irq = installation_files["irq_debug_tgz"]
print("Installing irq debug drivers.")
create_symlinks()
tar = tarfile.open(irq)
irq_folder_name = tar.getnames()[0]
tar.extractall()
tar.close()
print(irq_folder_name)
os.chdir(irq_folder_name)
os.system("make")
print("Installing module irq_debug.")
os.system("sudo insmod ./irq_debug.ko")
def install_mv_pipe():
print("Building mv_pipe_config...")
os.chdir(common.dname)
mv_pipe = installation_files["mv_pipe_config_zip"]
zip_ref = zipfile.ZipFile(mv_pipe)
zip_ref.extractall()
extracted_dir_name = zip_ref.namelist()[0]
zip_ref.close()
os.chdir(extracted_dir_name)
os.system("gcc mv_pipe_config.c -o mv_pipe_config")
os.system("sudo mkdir /delta")
os.system("sudo cp ./mv_pipe_config /delta/")
def load_bf_kdrv():
print("Loading bf_kdrv....")
print("Using SDE {} for loading bf_kdrv.".format(get_env_var('SDE')))
os.system(
"sudo {0}/bin/bf_kdrv_mod_load {0}".format(
get_env_var('SDE_INSTALL')))
def load_bf_kpkt():
print("Loading bf_kpkt....")
print("Using SDE {} for loading bf_kpkt.".format(get_env_var('SDE')))
os.system(
"sudo {0}/bin/bf_kpkt_mod_load {0}".format(
get_env_var('SDE_INSTALL')))