forked from LeoEkky/OpenAI-Codex-Code-Generation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.py
More file actions
148 lines (102 loc) · 3.08 KB
/
Copy pathkernel.py
File metadata and controls
148 lines (102 loc) · 3.08 KB
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
from __future__ import print_function
import os
import re
import shutil
import subprocess
import sys
import tempfile
# Package dependencies:
#
# build-essential
# libncurses5-dev
# libssl-dev
# -----------------------------------------------------------------------------
def main():
"""
Main program.
"""
build_dir = tempfile.mkdtemp()
os.chdir(build_dir)
print("Downloading kernel source...")
if not download_source():
print("Error downloading kernel source. Exiting...")
sys.exit(1)
print("Building kernel...")
if not build_kernel():
print("Error building kernel. Exiting...")
sys.exit(1)
print("Installing kernel...")
if not install_kernel():
print("Error installing kernel. Exiting...")
sys.exit(1)
print("Cleaning up...")
if not cleanup():
print("Error cleaning up. Exiting...")
sys.exit(1)
print("Finished.")
sys.exit(0)
# -----------------------------------------------------------------------------
def build_kernel():
"""
Build the kernel.
"""
# Configure the build.
if not run_command("./build_rpi_kernel.sh"):
return False
# Build the kernel.
if not run_command("make -j4"):
return False
return True
# -----------------------------------------------------------------------------
def build_modules():
"""
Build kernel modules.
"""
# Build the kernel modules.
if not run_command("make -C /lib/modules/$(uname -r)/build M=$(pwd) modules"):
return False
return True
# -----------------------------------------------------------------------------
def cleanup():
"""
Clean up the build directory.
"""
return True
# -----------------------------------------------------------------------------
def download_source():
"""
Download the kernel source.
"""
# Download the source.
if not run_command("wget https://github.com/raspberrypi/linux/archive/rpi-3.18.y.zip"):
return False
# Unzip the source.
if not run_command("unzip rpi-3.18.y.zip"):
return False
return True
# -----------------------------------------------------------------------------
def install_kernel():
"""
Install the kernel.
"""
# Install the kernel.
if not run_command("sudo make modules_install"):
return False
# Install the kernel headers.
if not run_command("sudo make headers_install"):
return False
return True
# -----------------------------------------------------------------------------
def run_command(command):
"""
Run a command.
"""
try:
subprocess.check_call(command, shell=True)
except subprocess.CalledProcessError as err:
print("Command failed: " + str(err))
return False
return True
# -----------------------------------------------------------------------------
if __name__ == "__main__":
main()