xref: /freebsd/sys/dev/cxgb/bin2h.pl (revision 63a938566d524836885917d95bd491aa4400b181)
1#!/usr/bin/perl -w
2
3#$FreeBSD$
4
5if ($#ARGV != 1) {
6  print "bin2h.pl <firmware> <headername>\n";
7  exit 1;
8}
9
10my $success = open INPUT, "$ARGV[0]";
11unless ($success) {
12  print "failed to open input\n";
13  exit 1;
14}
15$success = open OUTPUT, ">$ARGV[1].h";
16unless ($success) {
17  print "failed to open output\n";
18  exit 1;
19}
20
21
22my $license = <<END;
23/**************************************************************************
24
25SPDX-License-Identifier: BSD-2-Clause-FreeBSD
26
27Copyright (c) 2007-2009, Chelsio Inc.
28All rights reserved.
29
30Redistribution and use in source and binary forms, with or without
31modification, are permitted provided that the following conditions are met:
32
33 1. Redistributions of source code must retain the above copyright notice,
34    this list of conditions and the following disclaimer.
35
36 2. Neither the name of the Chelsio Corporation nor the names of its
37    contributors may be used to endorse or promote products derived from
38    this software without specific prior written permission.
39
40THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN22
48CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50POSSIBILITY OF SUCH DAMAGE.
51
52
53\$FreeBSD\$
54
55***************************************************************************/
56END
57print OUTPUT "$license\n";
58
59
60my $binary;
61
62my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
63 $atime,$mtime,$ctime,$blksize,$blocks)
64  = stat($ARGV[0]);
65
66
67print OUTPUT "#define U (unsigned char)\n\n";
68
69print OUTPUT "static unsigned int $ARGV[1]_length = $size;\n";
70print OUTPUT "static unsigned char $ARGV[1]" . "[$size]" . " = {\n";
71
72for (my $i = 0; $i < $size; $i += 4) {
73  my $number_read = read(INPUT, $binary, 4);
74  my ($a, $b, $c, $d) = unpack("C C C C", $binary);
75  $buf = sprintf("\tU 0x%02X, U 0x%02X, U 0x%02X, U 0x%02X, \n", $a, $b, $c, $d);
76  print OUTPUT $buf;
77}
78print OUTPUT "};\n";
79
80
81
82