blob: a1a76b8aa667ab4e15c43321e6f3ee153908a4cd [file] [log] [blame]
Andrew Geissler1fe918a2020-05-15 14:16:47 -05001#
2# isafw.py - Main classes for ISA FW
3#
4# Copyright (c) 2015 - 2016, Intel Corporation
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# * Redistributions of source code must retain the above copyright notice,
10# this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# * Neither the name of Intel Corporation nor the names of its contributors
15# may be used to endorse or promote products derived from this software
16# without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29from __future__ import absolute_import, print_function
30
31import sys
32import traceback
33try:
34 # absolute import
35 import isafw.isaplugins as isaplugins
36except ImportError:
37 # relative import when installing as separate modules
38 import isaplugins
39try:
40 from bb import error
41except ImportError:
42 error = print
43
44__all__ = [
45 'ISA_package',
46 'ISA_pkg_list',
47 'ISA_kernel',
48 'ISA_filesystem',
49 'ISA_config',
50 'ISA',
51]
52
53# classes for representing objects for ISA plugins
54
55# source package
56
57
58class ISA_package:
59 # pkg name (mandatory argument)
60 name = ""
61 # full version (mandatory argument)
62 version = ""
63 licenses = [] # list of licences for all subpackages
64 aliases = [] # list of alias names for packages if exist
65 source_files = [] # list of strings of source files
66 patch_files = [] # list of patch files to be applied
67 path_to_sources = "" # path to the source files
68
69# package list
70
71
72class ISA_pkg_list:
73 # image name (mandatory argument)
74 img_name = ""
75 # path to the pkg list file (mandatory argument)
76 path_to_list = ""
77
78# kernel
79
80
81class ISA_kernel:
82 # image name (mandatory argument)
83 img_name = ""
84 # path to the kernel config file (mandatory argument)
85 path_to_config = ""
86
87# filesystem
88
89
90class ISA_filesystem:
91 # image name (mandatory argument)
92 img_name = ""
93 type = "" # filesystem type
94 # path to the fs location (mandatory argument)
95 path_to_fs = ""
96
97# configuration of ISAFW
98# if both whitelist and blacklist is empty, all avaliable plugins will be used
99# if whitelist has entries, then only whitelisted plugins will be used from a set of avaliable plugins
100# if blacklist has entries, then the specified plugins won't be used even
101# if avaliable and even if specified in whitelist
102
103
104class ISA_config:
105 plugin_whitelist = "" # comma separated list of plugins to whitelist
106 plugin_blacklist = "" # comma separated list of plugins to blacklist
107 cacert = None # If set, a CA certificate file that replaces the system default one
108 reportdir = "" # location of produced reports
109 logdir = "" # location of produced logs
110 timestamp = "" # timestamp of the build provided by build system
111 full_reports = False # produce full reports for plugins, False by default
112 machine = "" # name of machine build is produced for
113 la_plugin_image_whitelist = ""# whitelist of images for violating license checks
114 la_plugin_image_blacklist = ""# blacklist of images for violating license checks
115 arch = "" # target architecture
116
117class ISA:
118 def call_plugins(self, methodname, *parameters, **keywords):
119 for name in isaplugins.__all__:
120 plugin = getattr(isaplugins, name)
121 method = getattr(plugin, methodname, None)
122 if not method:
123 # Not having init() is an error, everything else is optional.
124 if methodname == "init":
125 error("No init() defined for plugin %s.\n"
126 "Skipping this plugin." %
127 (methodname, plugin.getPluginName()))
128 continue
129 if self.ISA_config.plugin_whitelist and plugin.getPluginName() not in self.ISA_config.plugin_whitelist:
130 continue
131 if self.ISA_config.plugin_blacklist and plugin.getPluginName() in self.ISA_config.plugin_blacklist:
132 continue
133 try:
134 method(*parameters, **keywords)
135 except:
136 error("Exception in plugin %s %s():\n%s" %
137 (plugin.getPluginName(),
138 methodname,
139 traceback.format_exc()))
140
141 def __init__(self, ISA_config):
142 self.ISA_config = ISA_config
143 self.call_plugins("init", ISA_config)
144
145 def process_package(self, ISA_package):
146 self.call_plugins("process_package", ISA_package)
147
148 def process_pkg_list(self, ISA_pkg_list):
149 self.call_plugins("process_pkg_list", ISA_pkg_list)
150
151 def process_kernel(self, ISA_kernel):
152 self.call_plugins("process_kernel", ISA_kernel)
153
154 def process_filesystem(self, ISA_filesystem):
155 self.call_plugins("process_filesystem", ISA_filesystem)
156
157 def process_report(self):
158 self.call_plugins("process_report")