Advertisement
neochapay

Untitled

Oct 12th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 12.13 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. # Mer Kernel config specification checker
  3. # http://wiki.merproject.org/wiki/Adaptation_Guide
  4.  
  5. # CONFIG must be set to one of the permitted values "," seperated and
  6. # multiple values permitted
  7.  
  8. # y = set and enabled
  9. # m = set and module
  10. # n = must be unset (commented out)
  11. #
  12. # "value" = must be set to "value"
  13. # /regexp/ = "value" which matches regexp
  14. #
  15. # ! = Failure will be warned, not errored
  16.  
  17. # Known issues with the basic parser:
  18. # * # in regexps or strings cause issues if there's no trailing #
  19. # * can't have "," in /regexp/
  20.  
  21. use Text::ParseWords;
  22. use strict;
  23.  
  24. my $debug = 0;
  25. my %config;
  26.  
  27. while (<DATA>) {
  28.   next if /^\s*(#.*)?$/ ; # skip comments and blank lines
  29.   chomp;
  30.  
  31.   my ($conf, $allowed) = split(' ', $_, 2);
  32.  
  33.   # Remove and capture any trailing comment (dubious matching here
  34.   # since comments in a "" or // will be removed too)
  35.   my $comment;
  36.   if ($allowed =~ s/(#\s*)(.*)?$//) {
  37.     $comment = $2 if $2;
  38.   }
  39.  
  40.   # http://perldoc.perl.org/Text/ParseWords.html
  41.   my @allowed = parse_line(",", 1, $allowed);
  42.  
  43.   my $warning;
  44.   # Strip leading/trailing space for each value and check for warnings
  45.   foreach (@allowed) {
  46.     s/^\s+|\s+$//g;
  47.     $warning = 1 if $_ eq "!" ;
  48.   }
  49.  
  50.   # Each CONFIG_* has an array of allowed values, a comment and a flag
  51.   # to say it's only a warning (in which case we print the comment)
  52.   $config{$conf} = {allowed => \@allowed,
  53.                     comment => $comment,
  54.                     warning => $warning };
  55. }
  56.  
  57. print "\nScanning\n" if $debug;
  58. while (<>) {
  59.   next if /^\s*(#.*)?$/ ; # skip comments and blank lines
  60.   chomp;
  61.   my ($conf, $value) = split('=', $_, 2);
  62.  
  63.   # Only check CONFIG_* values we know about
  64.   next unless $config{$conf};
  65.  
  66.   my $c = $config{$conf};
  67.  
  68.   print "$conf matched, checking..." if $debug;
  69.   $c->{"value"} = $value; # Store the value for later reporting
  70.  
  71.   my $allowed = $c->{"allowed"};
  72.   for my $allow (@$allowed) {
  73.     if (substr($allow,1,1) eq '/') { # regexps
  74.       print "Do a regex match : \"$value\" =~ $allow\n" if $debug;
  75.  
  76.     } elsif (substr($allow,1,1) eq '"') { # strings
  77.       print "Do a string match : $allow == $value\n" if $debug;
  78.       if ($value eq $allow) {$c->{"valid"} = 1; }
  79.  
  80.     } else { # plain y/m values
  81.       print "match y/m : $value == $allow\n" if $debug;
  82.       if ($value eq $allow) {$c->{"valid"} = 1; }
  83.     }
  84.   }
  85.   if ($c->{"valid"}) { print "OK\n" if $debug;}
  86. }
  87.  
  88. print "Results\n" if $debug;
  89. my $fatal = 0;
  90. for my $conf (keys %config) {
  91.   my $c = $config{$conf};
  92.  
  93.   if (! $c->{"valid"}) { # Check for 'n' case
  94.     foreach my $allow (@{$c->{"allowed"}}) {
  95.       if (("$allow" eq "n") and ! $c->{"value"}) {
  96.         $c->{"valid"} = 1;
  97.       }
  98.     }
  99.   }
  100.  
  101.   # Now report
  102.   if (! $c->{"valid"}) {
  103.     print defined($c->{"warning"}) ? "WARNING: " : "ERROR: ";
  104.     print "$conf is invalid\n";
  105.     if ($c->{"value"}) {
  106.       print "Value is: ". $c->{"value"} ."\n";
  107.     } else {
  108.       print "It is unset\n";
  109.     }
  110.     print "Allowed values : ".join(", ", @{$c->{"allowed"}}) ."\n";
  111.     print "Comment says: ". $c->{"comment"}."\n\n";
  112.     if (! $c->{"warning"}) {
  113.       $fatal = 1;
  114.     }
  115.   }
  116. }
  117. exit $fatal;
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. __DATA__
  127. CONFIG_ANDROID_LOW_MEMORY_KILLER        n # not tested with Mer
  128. CONFIG_ANDROID_PARANOID_NETWORK y,n       # not tested with Mer
  129. CONFIG_AUDIT                    n,!     # systemd: Either disable here or in cmdline http://cgit.freedesktop.org/systemd/systemd/commit/README?id=77b6e19458f37cfde127ec6aa9494c0ac45ad890
  130. CONFIG_AUTOFS4_FS               y,m,!   # systemd (optional): http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  131. CONFIG_BRIDGE                   y,m,!   # connman (optional): support tethering, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=19fe7cad485afa6a7a5cc4aa75615ce8b7b8d376
  132. CONFIG_IP_NF_TARGET_MASQUERADE  y,m,!   # connman (optional): support tethering, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=19fe7cad485afa6a7a5cc4aa75615ce8b7b8d376
  133. CONFIG_IP_NF_IPTABLES           y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=41f37125887cb9208da2441e350e1e3324c17ee6
  134. CONFIG_IP_MULTIPLE_TABLES       y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=41f37125887cb9208da2441e350e1e3324c17ee6
  135. CONFIG_NETFILTER_NETLINK_ACCT   y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=41f37125887cb9208da2441e350e1e3324c17ee6
  136. CONFIG_NETFILTER_XT_MATCH_NFACCT        y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=41f37125887cb9208da2441e350e1e3324c17ee6
  137. CONFIG_NETFILTER_XT_CONNMARK            y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=115cb9cbd3cdda00784e58a4ea12b42d128732b4
  138. CONFIG_NETFILTER_XT_TARGET_CONNMARK     y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=115cb9cbd3cdda00784e58a4ea12b42d128732b4
  139. CONFIG_NETFILTER_XT_MATCH_CONNMARK      y,m,!   # connman (optional): for routing and statistic support in sessions, http://git.kernel.org/cgit/network/connman/connman.git/commit/README?id=115cb9cbd3cdda00784e58a4ea12b42d128732b4
  140. CONFIG_CGROUPS                  y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  141. CONFIG_CGROUP_FREEZER           y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  142. CONFIG_CGROUP_DEVICE            y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  143. CONFIG_CGROUP_CPUACCT           y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  144. CONFIG_CGROUP_MEM_RES_CTLR      y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  145. CONFIG_CGROUP_MEM_RES_CTLR_SWAP y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  146. CONFIG_CGROUP_MEM_RES_CTLR_KMEM y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  147. CONFIG_CGROUP_PERF              y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  148. CONFIG_CGROUP_SCHED             y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  149. CONFIG_BLK_CGROUP               y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  150. CONFIG_NET_CLS_CGROUP           y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  151. CONFIG_NETPRIO_CGROUP           y,!     # systemd (optional): http://0pointer.de/blog/projects/cgroups-vs-cgroups.html
  152. CONFIG_DEVTMPFS                 y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  153. CONFIG_DUMMY                    n
  154. CONFIG_FHANDLE                  y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=001809282918f273d372f1ee09d10b783c18a474
  155. CONFIG_SCHEDSTATS               y,!     # systemd-bootchart (optional): http://cgit.freedesktop.org/systemd/systemd/commit/README?id=f1c24fea94e19cf2108abbeed1d36ded7102ab98
  156. CONFIG_SCHED_DEBUG              y,!     # systemd-bootchart (optional): http://cgit.freedesktop.org/systemd/systemd/commit/README?id=f1c24fea94e19cf2108abbeed1d36ded7102ab98
  157. CONFIG_NLS_UTF8                 y       # Ensure that we support UTF8 filenames.
  158. CONFIG_BT                       y,!     # Bluez (optional): Needed if bluez used as bluetooth stack
  159. CONFIG_BT_RFCOMM                y,!     # Bluez (optional): Needed if bluez used as bluetooth stack
  160. CONFIG_BT_HCIUART               y,!     # Bluez (optional): Needed if bluez used as bluetooth stack
  161. CONFIG_BT_HCIUART_H4            y,!     # Bluez (optional): Needed if bluez used as bluetooth stack
  162. CONFIG_BT_MSM_SLEEP             n,!     # Bluez (optional): Causes problems with bluez thus disabling is recommended.
  163. CONFIG_HIDRAW                   y,m,!   # optional: Support HID devices
  164. CONFIG_UNIX                     y       # UNIX sockets option is required to run Mer
  165. CONFIG_SYSVIPC                  y       # Inter Process Communication option is required to run Mer
  166. CONFIG_EXT4_FS                  y,m,!   # Mer uses ext4 as rootfs by default
  167. CONFIG_FANOTIFY                 y,!     # optional, required for systemd readahead.
  168. CONFIG_HOTPLUG                  y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  169. CONFIG_INOTIFY_USER             y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  170. CONFIG_IPV6                     y,m,!   # systemd: http://cgit.freedesktop.org/systemd/systemd/tree/README#n37
  171. CONFIG_RTC_DRV_CMOS             y,!     # optional, but highly recommended
  172. CONFIG_SIGNALFD                 y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  173. CONFIG_TIMERFD                  y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  174. CONFIG_EPOLL                    y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  175. CONFIG_NET                      y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=41938693e76c32161d2b3b83253ce996468cbf9b
  176. CONFIG_SYSFS                    y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  177. CONFIG_PROC_FS                  y       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=06d461ee6f3da6650e6d023d7828455752d70b0b
  178. CONFIG_SYSFS_DEPRECATED         n       # systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  179. CONFIG_TMPFS_POSIX_ACL          y,!     # systemd (optional): strongly recommended, if you want pam_systemd.so to setup your "seats". http://cgit.freedesktop.org/systemd/systemd/commit/README?id=77b6e19458f37cfde127ec6aa9494c0ac45ad890
  180. CONFIG_TMPFS_XATTR              y,!     # systemd (optional): strongly recommended, http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  181. CONFIG_SECCOMP                  y,!     # systemd (optional): strongly recommended, http://cgit.freedesktop.org/systemd/systemd/commit/README?id=f28cbd0382ca53baa99803bbc907a469fbf68128
  182. CONFIG_TUN                      y,m,!   # ofono: http://git.kernel.org/?p=network/ofono/ofono.git;a=blob;f=README;h=413d789e5f9e96024986f5116d3c8aff0c9f15b8;hb=HEAD#l28
  183. CONFIG_UEVENT_HELPER_PATH       "", !   # should be empty, if you want to use systemd without initramfs. Also systemd: http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  184. CONFIG_FW_LOADER_USER_HELPER    n,!     # it's actually needed by some Lollipop based devices; systemd(optional): http://cgit.freedesktop.org/systemd/systemd/commit/README?id=713bc0cfa477ca1df8769041cb3dbc83c10eace2
  185. CONFIG_VT                       y       # Required for virtual consoles
  186. CONFIG_LBDAF                    y,!     # ext4 filesystem requires this in order to support filesysetms with huge_file feature, which is enabled by default by mke2fs.ext4
  187. CONFIG_WATCHDOG_NOWAYOUT        y,!     # If device uses watchdogs with dsme (https://github.com/nemomobile/dsme), this option should be enabled or watchdog does not protect the device in case dsme crashes.
  188. CONFIG_CHECKPOINT_RESTORE       y,!     # rich-core-dumper (https://github.com/mer-tools/sp-rich-core/) needs this to collect all data for environment recreation.
  189. CONFIG_RD_GZIP                  y       # Required by hybris-boot Android.mk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement