3 # Script for generating redboot configs, based on brcmImage.pl
5 # Copyright (C) 2015 Álvaro Fernández Rojas <noltari@gmail.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 o => 'redboot.script',
37 getopts("r:k:o:s:f:a:l:t:vh", \%arg);
39 die "usage: $prog ~opts~
41 -r <file> : input rootfs file
42 -k <file> : input kernel file
43 -o <file> : output image file, default $arg{o}
44 -s <size_kb> : redboot script size, default ".sprintf('%d', parse_num($arg{s}))."
45 -f <baseaddr> : flash base, default ".sprintf('0x%x', parse_num($arg{f}))."
46 -a <loadaddr> : Kernel load address, default ".sprintf('0x%x', parse_num($arg{a}))."
47 -l <linux_kb> : linux partition size, default ".sprintf('0x%x', parse_num($arg{l}))."
48 -t <timeout> : redboot script timeout, default ".sprintf('%d', parse_num($arg{t}))."
50 -h : help, version $version
53 $prog -k kern -r rootfs
54 " if $arg{h} || !$arg{k} || !$arg{r};
59 if (index(lc($num), lc("0x")) == 0) {
68 my $kernel_off = parse_num($arg{s});
69 my $kernel_addr = parse_num($arg{f});
70 my $kernel_len = stat($arg{k})->size;
72 my $rootfs_off = $kernel_off + $kernel_len;
73 my $rootfs_addr = $kernel_addr + $kernel_len;
74 my $rootfs_len = parse_num($arg{l}) - $kernel_len;
75 my $rootfs_size = stat($arg{r})->size;
77 my $load_addr = parse_num($arg{a});
79 my $timeout = parse_num($arg{t});
82 printf "kernel_off: 0x%x(%u)\n", $kernel_off, $kernel_off;
83 printf "kernel_addr: 0x%x(%u)\n", $kernel_addr, $kernel_addr;
84 printf "kernel_len: 0x%x(%u)\n", $kernel_len, $kernel_len;
86 printf "rootfs_off: 0x%x(%u)\n", $rootfs_off, $rootfs_off;
87 printf "rootfs_addr: 0x%x(%u)\n", $rootfs_addr, $rootfs_addr;
88 printf "rootfs_len: 0x%x(%u)\n", $rootfs_len, $rootfs_len;
89 printf "rootfs_size: 0x%x(%u)\n", $rootfs_size, $rootfs_size;
93 printf FO "fis init -f\n";
95 printf FO "fconfig boot_script true\n";
96 printf FO "fconfig boot_script_data\n";
97 printf FO "fis load -b 0x%x -d kernel\n", $load_addr;
98 printf FO "exec -c \"noinitrd\" 0x%x\n", $load_addr;
100 printf FO "fconfig boot_script_timeout %d\n", $timeout;
102 printf FO "fis create -o 0x%x -f 0x%x -l 0x%x kernel\n", $kernel_off, $kernel_addr, $kernel_len;
104 printf FO "fis create -o 0x%x -s 0x%x -f 0x%x -l 0x%x rootfs\n", $rootfs_off, $rootfs_size, $rootfs_addr, $rootfs_len;