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