The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/tools/fw_stub.awk

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 #!/usr/bin/awk -f
    2 
    3 #-
    4 # Copyright (c) 2006 Max Laier.
    5 # All rights reserved.
    6 #
    7 # Redistribution and use in source and binary forms, with or without
    8 # modification, are permitted provided that the following conditions
    9 # are met:
   10 # 1. Redistributions of source code must retain the above copyright
   11 #    notice, this list of conditions and the following disclaimer.
   12 # 2. Redistributions in binary form must reproduce the above copyright
   13 #    notice, this list of conditions and the following disclaimer in the
   14 #    documentation and/or other materials provided with the distribution.
   15 #
   16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS'' AND
   17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26 # SUCH DAMAGE.
   27 #
   28 # $FreeBSD: releng/6.4/sys/tools/fw_stub.awk 166891 2007-02-22 19:10:48Z luigi $
   29 
   30 #
   31 # Script to generate module .c file from a list of firmware images
   32 #
   33 
   34 function usage ()
   35 {
   36         print "usage: fw_stub <firmware:name>* [-m modname] [-c outfile]";
   37         exit 1;
   38 }
   39 
   40 #   These are just for convenience ...
   41 function printc(s)
   42 {
   43         if (opt_c)
   44                 print s > ctmpfilename;
   45         else
   46                 print s > "/dev/stdout";
   47 }
   48 
   49 BEGIN {
   50 
   51 #
   52 #   Process the command line.
   53 #
   54 
   55 num_files = 0;
   56 
   57 for (i = 1; i < ARGC; i++) {
   58         if (ARGV[i] ~ /^-/) {
   59                 #
   60                 #   awk doesn't have getopt(), so we have to do it ourselves.
   61                 #   This is a bit clumsy, but it works.
   62                 #
   63                 for (j = 2; j <= length(ARGV[i]); j++) {
   64                         o = substr(ARGV[i], j, 1);
   65                         if (o == "c") {
   66                                 if (length(ARGV[i]) > j) {
   67                                         opt_c = substr(ARGV[i], j + 1);
   68                                         break;
   69                                 }
   70                                 else {
   71                                         if (++i < ARGC)
   72                                                 opt_c = ARGV[i];
   73                                         else
   74                                                 usage();
   75                                 }
   76                         } else if (o == "m") {
   77                                 if (length(ARGV[i]) > j) {
   78                                         opt_m = substr(ARGV[i], j + 1);
   79                                         break;
   80                                 }
   81                                 else {
   82                                         if (++i < ARGC)
   83                                                 opt_m = ARGV[i];
   84                                         else
   85                                                 usage();
   86                                 }
   87                         } else
   88                                 usage();
   89                 }
   90         } else {
   91                 split(ARGV[i], curr, ":");
   92                 filenames[num_files] = curr[1];
   93                 if (length(curr[2]) > 0)
   94                         shortnames[num_files] = curr[2];
   95                 else
   96                         shortnames[num_files] = curr[2];
   97                 if (length(curr[3]) > 0)
   98                         versions[num_files] = int(curr[3]);
   99                 else
  100                         versions[num_files] = 0;
  101                 num_files++;
  102         }
  103 }
  104 
  105 if (!num_files || !opt_m)
  106         usage();
  107 
  108 cfilename = opt_c;
  109 ctmpfilename = cfilename ".tmp";
  110 
  111 printc("#include <sys/param.h>\
  112 #include <sys/errno.h>\
  113 #include <sys/kernel.h>\
  114 #include <sys/module.h>\
  115 #include <sys/linker.h>\
  116 #include <sys/firmware.h>\n");
  117 
  118 for (file_i = 0; file_i < num_files; file_i++) {
  119         symb = filenames[file_i];
  120         # '-', '.' and '/' are converted to '_' by ld/objcopy
  121         gsub(/-|\.|\//, "_", symb);
  122         printc("extern char _binary_" symb "_start[], _binary_" symb "_end[];");
  123 }
  124 
  125 printc("\nstatic int\n"\
  126 opt_m "_fw_modevent(module_t mod, int type, void *unused)\
  127 {\
  128         const struct firmware *fp, *parent;\
  129         int error;\
  130         switch (type) {\
  131         case MOD_LOAD:");
  132 
  133 for (file_i = 0; file_i < num_files; file_i++) {
  134         short = shortnames[file_i];
  135         symb = filenames[file_i];
  136         version = versions[file_i];
  137         # '-', '.' and '/' are converted to '_' by ld/objcopy
  138         gsub(/-|\.|\//, "_", symb);
  139 
  140         reg = "\t\tfp = ";
  141         reg = reg "firmware_register(\"" short "\", _binary_" symb "_start , ";
  142         reg = reg "(size_t)(_binary_" symb "_end - _binary_" symb "_start), ";
  143         reg = reg version ", ";
  144 
  145         if (file_i == 0)
  146                 reg = reg "NULL);";
  147         else
  148                 reg = reg "parent);";
  149 
  150         printc(reg);
  151 
  152         printc("\t\tif (fp == NULL)");
  153         printc("\t\t\tgoto fail_" file_i ";");
  154         if (file_i == 0)
  155                 printc("\t\tparent = fp;");
  156 }
  157 
  158 printc("\t\treturn (0);");
  159 
  160 for (file_i = num_files - 1; file_i > 0; file_i--) {
  161         printc("\tfail_" file_i ":")
  162         printc("\t\t(void)firmware_unregister(\"" shortnames[file_i - 1] "\");");
  163 }
  164 
  165 printc("\tfail_0:");
  166 printc("\t\treturn (ENXIO);");
  167 
  168 printc("\tcase MOD_UNLOAD:");
  169 
  170 for (file_i = 1; file_i < num_files; file_i++) {
  171         printc("\t\terror = firmware_unregister(\"" shortnames[file_i] "\");");
  172         printc("\t\tif (error)");
  173         printc("\t\t\treturn (error);");
  174 }
  175 
  176 printc("\t\terror = firmware_unregister(\"" shortnames[0] "\");");
  177 
  178 printc("\t\treturn (error);\
  179         }\
  180         return (EINVAL);\
  181 }\
  182 \
  183 static moduledata_t " opt_m "_fw_mod = {\
  184         \"" opt_m "_fw\",\
  185         " opt_m "_fw_modevent,\
  186         0\
  187 };\
  188 DECLARE_MODULE(" opt_m "_fw, " opt_m "_fw_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);\
  189 MODULE_VERSION(" opt_m "_fw, 1);\
  190 MODULE_DEPEND(" opt_m "_fw, firmware, 1, 1, 1);\
  191 ");
  192 
  193 if (opt_c)
  194         if ((rc = system("mv -f " ctmpfilename " " cfilename))) {
  195                 print "'mv -f " ctmpfilename " " cfilename "' failed: " rc \
  196                     > "/dev/stderr";
  197                 exit 1;
  198         }
  199 
  200 exit 0;
  201 
  202 }

Cache object: b15822bbb5cc4005fa3450a783dc71be


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.