2
0

redboot-script.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env perl
  2. #
  3. # Script for generating redboot configs, based on brcmImage.pl
  4. #
  5. # Copyright (C) 2015 Álvaro Fernández Rojas <noltari@gmail.com>
  6. #
  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.
  11. #
  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.
  16. #
  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.
  20. #
  21. use strict;
  22. use Getopt::Std;
  23. use File::stat;
  24. my $version = "0.1";
  25. my %arg = (
  26. o => 'redboot.script',
  27. s => 0x1000,
  28. f => 0xbe430000,
  29. a => 0x80010000,
  30. l => 0x7c0000,
  31. t => 20,
  32. );
  33. my $prog = $0;
  34. $prog =~ s/^.*\///;
  35. getopts("r:k:o:s:f:a:l:t:vh", \%arg);
  36. die "usage: $prog ~opts~
  37. -r <file> : input rootfs file
  38. -k <file> : input kernel file
  39. -o <file> : output image file, default $arg{o}
  40. -s <size_kb> : redboot script size, default ".sprintf('%d', parse_num($arg{s}))."
  41. -f <baseaddr> : flash base, default ".sprintf('0x%x', parse_num($arg{f}))."
  42. -a <loadaddr> : Kernel load address, default ".sprintf('0x%x', parse_num($arg{a}))."
  43. -l <linux_kb> : linux partition size, default ".sprintf('0x%x', parse_num($arg{l}))."
  44. -t <timeout> : redboot script timeout, default ".sprintf('%d', parse_num($arg{t}))."
  45. -v : be more verbose
  46. -h : help, version $version
  47. EXAMPLES:
  48. $prog -k kern -r rootfs
  49. " if $arg{h} || !$arg{k} || !$arg{r};
  50. sub parse_num
  51. {
  52. my $num = @_[0];
  53. if (index(lc($num), lc("0x")) == 0) {
  54. return hex($num);
  55. } else {
  56. return $num + 0;
  57. }
  58. }
  59. sub gen_script
  60. {
  61. my $kernel_off = parse_num($arg{s});
  62. my $kernel_addr = parse_num($arg{f});
  63. my $kernel_len = stat($arg{k})->size;
  64. my $rootfs_off = $kernel_off + $kernel_len;
  65. my $rootfs_addr = $kernel_addr + $kernel_len;
  66. my $rootfs_len = parse_num($arg{l}) - $kernel_len;
  67. my $rootfs_size = stat($arg{r})->size;
  68. my $load_addr = parse_num($arg{a});
  69. my $timeout = parse_num($arg{t});
  70. if ($arg{v}) {
  71. printf "kernel_off: 0x%x(%u)\n", $kernel_off, $kernel_off;
  72. printf "kernel_addr: 0x%x(%u)\n", $kernel_addr, $kernel_addr;
  73. printf "kernel_len: 0x%x(%u)\n", $kernel_len, $kernel_len;
  74. printf "rootfs_off: 0x%x(%u)\n", $rootfs_off, $rootfs_off;
  75. printf "rootfs_addr: 0x%x(%u)\n", $rootfs_addr, $rootfs_addr;
  76. printf "rootfs_len: 0x%x(%u)\n", $rootfs_len, $rootfs_len;
  77. printf "rootfs_size: 0x%x(%u)\n", $rootfs_size, $rootfs_size;
  78. }
  79. open(FO, ">$arg{o}");
  80. printf FO "fis init -f\n";
  81. printf FO "\n";
  82. printf FO "fconfig boot_script true\n";
  83. printf FO "fconfig boot_script_data\n";
  84. printf FO "fis load -b 0x%x -d kernel\n", $load_addr;
  85. printf FO "exec -c \"noinitrd\" 0x%x\n", $load_addr;
  86. printf FO "\n";
  87. printf FO "fconfig boot_script_timeout %d\n", $timeout;
  88. printf FO "\n";
  89. printf FO "fis create -o 0x%x -f 0x%x -l 0x%x kernel\n", $kernel_off, $kernel_addr, $kernel_len;
  90. printf FO "\n";
  91. 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;
  92. printf FO "\n";
  93. printf FO "reset\n";
  94. close FO;
  95. }
  96. # MAIN
  97. gen_script();