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 | # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
# Copyright (C) 2016 DEWETRON GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""The kmodule plugin can be used as part of a kernel build
WARNING: this plugin's API is unstable. The cross compiling support is
experimental.
The following kernel specific options are provided by this plugin:
- kernel-source-dir:
(string; default: None)
the path the kernel/build part the module is referring to.
- kernel-install-dir:
(string; default: None)
Usually this has to be $SNAPCRAFT_STAGE. This is the place the
kernel module is installed to.
- module-source-dir:
(string; default: None)
the directoy the sources for the kernel module are located.
"""
import logging
import os
import snapcraft
from snapcraft import common
logger = logging.getLogger(__name__)
class KModulePlugin(snapcraft.BasePlugin):
@classmethod
def schema(cls):
schema = super().schema()
schema['properties']['kernel-source-dir'] = {
'type': 'string',
'default': '',
}
schema['properties']['module-source-dir'] = {
'type': 'string',
'default': '',
}
schema['properties']['kernel-install-dir'] = {
'type': 'string',
'default': '',
}
schema['required'].append('kernel-source-dir')
schema['required'].append('kernel-install-dir')
schema['required'].append('module-source-dir')
return schema
def __init__(self, name, options):
super().__init__(name, options)
self.make_targets = []
self.make_cmd = [
'make', '-j{}'.format(common.get_parallel_build_count())]
if logger.isEnabledFor(logging.DEBUG):
self.make_cmd.append('V=1')
def build(self):
"""
This is the step that follows pull. Each part is built in its
`parts/part-name/build` directory and installs itself into
`parts/part-name/install`.
"""
super().build()
make_cmd = self.make_cmd.copy()
kernel_source_dir = self.options.kernel_source_dir
kernel_build_dir = self.options.kernel_source_dir
module_source_dir = self.options.module_source_dir
self.run(make_cmd +
['-C', kernel_source_dir,
'O={}'.format(kernel_build_dir),
'M={}'.format(os.path.join(self.builddir, module_source_dir))])
self.run(make_cmd +
['INSTALL_MOD_PATH={}'.format(self.options.kernel_install_dir),
'-C', kernel_source_dir,
'M={}'.format(os.path.join(self.builddir, module_source_dir)),
'modules_install'])
---------
Example:
name: trionet-kernel
version: 4.4.0
summary: ubuntu xenial kernel with trion kernel module
description: A standard kernel but with the trion kernel module included. This is a driver for DEWETRON TRION measurement devices.
type: kernel
parts:
kernel:
plugin: kernel
source: git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git
source-type: git
kdefconfig: [defconfig]
kconfigfile: config-4.4.0-15-generic # overwrites kdefconfig
kconfigs:
- CONFIG_LOCALVERSION="-trion"
- CONFIG_DEBUG_INFO=n
- CONFIG_SQUASHFS=m
kernel-initrd-modules:
- squashfs
kernel-with-firmware: False
kernel-initrd-firmware: []
kernel-image-target: bzImage
kernel-device-trees: []
kernel-os-snap: xenial-preinstalled-core-amd64.os.snap
trion-ko:
plugin: kmodule
source: /home/glaure/Mercurial/SW_APP/driver/trion/trion-src.tar.gz
kernel-source-dir: ../../kernel/build
kernel-install-dir: $SNAPCRAFT_STAGE
module-source-dir: trion
after:
- kernel
|