This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
drivers.py
142 lines (113 loc) · 4.26 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
import os
import tarfile
import constants
from common import execute_cmd_n_get_output, get_env_var, dname, \
create_symlinks, \
is_ubuntu, get_switch_model, get_from_setting_dict
from constants import sde_module_bf_kdrv_string_value, \
sde_module_bf_kpkt_string_value
installation_files = {
"irq_debug_tgz": "./irq_debug.tgz"
}
def get_sde_modules():
return get_from_setting_dict(constants.sde_details_node, constants.sde_modules_node)
def load_and_verify_kernel_modules():
output = execute_cmd_n_get_output('lsmod')
bf_mod = True
sde_module_names = get_sde_modules()
if sde_module_names is not None:
for module_name in sde_module_names:
if module_name == sde_module_bf_kdrv_string_value:
if module_name not in output:
load_bf_kdrv()
else:
print('Module {} already loaded'.format(module_name))
elif module_name == sde_module_bf_kpkt_string_value:
if module_name not in output:
load_bf_kpkt()
else:
print('Module {} already loaded'.format(module_name))
else:
print('Invalid module to load - {}.'.format(module_name))
exit(0)
else:
print('Select at-least one SDE module to load in settings.xml')
exit(0)
output = execute_cmd_n_get_output('lsmod')
if not any(mod in output for mod in [sde_module_bf_kdrv_string_value,
sde_module_bf_kpkt_string_value]):
bf_mod = False
print("ERROR: Neither of {0}/{1} module loaded.".
format(sde_module_bf_kdrv_string_value,
sde_module_bf_kpkt_string_value))
# Load switch specific kernel modules
if get_switch_model() == constants.bf2556x_1t:
return bf_mod and load_and_verify_kernel_modules_bf2556()
else:
return bf_mod and load_and_verify_kernel_modules_bf6064()
def load_drivers():
print('Loading kernel modules.')
if not load_and_verify_kernel_modules():
print("ERROR:Some kernel modules are not loaded.")
exit(0)
def load_and_verify_kernel_modules_bf6064():
execute_cmd_n_get_output('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 = ""
def load_and_verify_kernel_modules_bf2556():
output = execute_cmd_n_get_output('lsmod')
irq_debug = True
if 'irq_debug' not in output:
install_irq_debug()
# Verify that modules are loaded.
output = execute_cmd_n_get_output('lsmod')
if 'irq_debug' not in output:
irq_debug = False
print("ERROR:irq_debug is not loaded.")
return irq_debug
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 clean")
os.system("make")
print("Installing module irq_debug.")
os.system("sudo insmod ./irq_debug.ko")
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')))