3 # Copyright (C) 2009 Henk Vergonet <Henk.Vergonet@gmail.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Replacement for brcmImagebuilder
24 # Use this software at your own risk.
27 # 2009-01-01 Henk.Vergonet at gmail.com
35 o
=> 'bcm963xx_fs_kernel',
47 getopts
("r:k:o:lc:b:s:f:i:a:e:tpvh", \
%arg);
49 die "usage: $prog ~opts~
51 -r <file> : input rootfs file
52 -k <file> : input kernel file
53 -o <file> : output image file, default $arg{o}
54 -l : littleendian system, default ".($arg{l
} ?
'yes' : 'no')."
55 -c <chipid> : default $arg{c}
56 -b <boardid> : default $arg{b}
57 -s <size_kb> : erase sise flash, default $arg{s}
58 -f <baseaddr> : flash base, default ".sprintf('0x%x', $arg{f
})."
59 -x <cfelen> : length of cfe, default ".sprintf('0x%x', $arg{x
})."
60 -i : 2=dual image, default $arg{i}
62 -a <loadaddr> : Kernel load address, default ".sprintf('0x%x', $arg{a
})."
63 -e <entryaddr>: Kernel entry address, default ".sprintf('0x%x', $arg{e
})."
64 -t : Prefix kernel with load,entry,size
66 -p : Add a 'gOtO' partition
69 -h : help, version $version
72 $prog -k kern -r rootfs
73 " if $arg{h
} || !$arg{k
} || !$arg{r
};
77 open my $fh, $_[0] or die "open $_[0]: $!";
78 local $/; # Set input to "slurp" mode.
86 my $p = $_[0] % $_[1];
87 return ($p ?
$_[1] - $p : 0);
92 my ($buf, $off, $bs) = @_[0..2];
93 $buf .= chr(255) x Padlen
(length($buf) + $off, $bs);
99 my ($k, $f) = @_[0..1];
100 my $tmp = $arg{x
} + 0x100 + $arg{f
};
102 # regular: rootfs+kernel
103 my ($img, $fa, $ka) = ( $f.$k, $tmp, $tmp + length($f) );
105 # test: kernel+rootfs
106 # my ($img, $fa, $ka) = ( $k.$f, $tmp + length($k), $tmp );
108 $fa = 0 unless length($f);
110 my $hdr = pack("a4a20a14a6a16a2a10a12a10a12a10a12a10a2a2a74Na16",
116 ($arg{l
} ?
'0' : '1'),
124 ($arg{i
}==2 ?
'1' : '0'),
125 '', # if 1, the image is INACTIVE; if 0, active
127 ~crc32
($k, crc32
($f)),
129 $hdr .= pack('Na16', ~crc32
($hdr), '');
131 printf "kernel at 0x%x length 0x%x(%u)\n", $ka, length($k), length($k)
133 printf "rootfs at 0x%x length 0x%x(%u)\n", $fa, length($f), length($f)
136 open(FO
, ">$arg{o}");
144 my $kern = Read_Image
$arg{k
};
145 my $root = Read_Image
$arg{r
};
147 $kern = pack('NNN', $arg{a
}, $arg{e
}, length($kern)).$kern if $arg{t
};
149 # specific fixup for the CFE that expects rootfs-kernel order
151 $kern = Pad
($kern, 0x10c, $arg{s
} * 1024);
152 my $dummy_root = pack('a4NN',
155 length($root)+Padlen
(length($root), $arg{s
} * 1024)
161 bcmImage
($kern, $root);
This page took 0.055018 seconds and 5 git commands to generate.