linksys-image.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. #
  4. # Copyright (C) 2024 OpenWrt.org
  5. #
  6. # This script creates a tar file for the Linksys switches of the LGS3xxC/LGS3xxMPC
  7. # series. It contains not only the OpenWrt firmware but additional scripts that
  8. # are needed for the upgrade.
  9. #
  10. # ./linksys-image.py <ImageFile> <ImageFileOut> <LinksysModel>
  11. #
  12. # Known values for LinksysModel are currently
  13. #
  14. # LGS310MPC 60402010
  15. # LGS310C 60402060
  16. # LGS328PC 60401070
  17. # LGS328PC(RTL8218D) 60401080
  18. # LGS310MPCv2 60402090
  19. # LGS328MPC 60412020
  20. # LGS328C 60412040
  21. # LGS328MPCv2 60412060
  22. # LGS352MPC 60422030
  23. # LGS352C 60422050
  24. # LGS352MPCv2 60422070
  25. # The check script that verifies if the images matches the hardware model
  26. gen_imagecheck() {
  27. echo '#!/bin/sh'
  28. echo 'if [ "$1" = "'${1}'" ]; then'
  29. echo 'echo 0'
  30. echo 'else'
  31. echo 'echo 1'
  32. echo 'fi'
  33. }
  34. # Generic attributes
  35. gen_fwinfo() {
  36. echo 'FW_VERSION=1.01.100\nBOOT_VERSION=01.00.01'
  37. }
  38. # NOR upgrade script. It allows to install OpenWrt only to first partition.
  39. gen_nor_upgrade() {
  40. echo '#!/bin/sh'
  41. echo 'flash_bank=65536'
  42. echo 'filesize=`stat --format=%s ./series_vmlinux.bix`'
  43. echo 'num_bank=`expr \( ${filesize} + ${flash_bank} - 1 \) / ${flash_bank}`'
  44. echo 'filesize_bank=`expr ${num_bank} \* ${flash_bank}`'
  45. echo 'case $1 in'
  46. echo '1)'
  47. echo 'mtd_debug erase $2 0 ${filesize_bank} >/dev/null 2>&1'
  48. echo 'mtd_debug write $2 0 ${filesize} ./series_vmlinux.bix >/dev/null 2>&1'
  49. echo 'mtd_debug read $2 0 100 image1.img >/dev/null 2>&1'
  50. echo 'CreateImage -r ./image1.img > /tmp/app/image1.txt'
  51. echo 'echo 0'
  52. echo ';;'
  53. echo '*)'
  54. echo 'echo 1'
  55. echo 'esac'
  56. }
  57. # NAND upgrade script. It allows to install OpenWrt only to first partition.
  58. gen_nand_upgrade() {
  59. echo '#!/bin/sh'
  60. echo 'case $1 in'
  61. echo '1)'
  62. echo 'flash_eraseall $2 >/dev/null 2>&1'
  63. echo 'nandwrite -p $2 ./series_vmlinux.bix >/dev/null 2>&1'
  64. echo 'mtd_debug read $2 0 100 image1.img >/dev/null 2>&1'
  65. echo 'CreateImage -r ./image1.img > /tmp/app/image1.txt'
  66. echo 'echo 0'
  67. echo ';;'
  68. echo '*)'
  69. echo 'echo 1'
  70. echo 'esac'
  71. }
  72. tmpdir="$( mktemp -d 2> /dev/null )"
  73. imgdir=$tmpdir/image
  74. mkdir $imgdir
  75. gen_imagecheck $3 > $imgdir/iss_imagecheck.sh
  76. gen_nor_upgrade > $imgdir/iss_imageupgrade.sh
  77. gen_nand_upgrade > $imgdir/iss_nand_imageupgrade.sh
  78. gen_fwinfo > $imgdir/firmware_information.txt
  79. chmod +x $imgdir/iss_imagecheck.sh
  80. chmod +x $imgdir/iss_imageupgrade.sh
  81. chmod +x $imgdir/iss_nand_imageupgrade.sh
  82. cp $1 $imgdir/series_vmlinux.bix
  83. tar cf $2 -C $tmpdir image/
  84. rm -rf $tmpdir