Untitled


SUBMITTED BY: Guest

DATE: Sept. 5, 2012, 11:53 a.m.

FORMAT: Text only

SIZE: 3.0 kB

HITS: 1480

  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2010 Matthias Buecher (http://www.maddes.net/)
  4. #
  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.
  9. # http://www.gnu.org/licenses/gpl-2.0.txt
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. UIMAGE=$1
  21. # check for uImage magic word
  22. # http://git.denx.de/cgi-bin/gitweb.cgi?p=u-boot.git;a=blob;f=include/image.h
  23. echo 'Checking for uImage magic word...'
  24. MAGIC=`dd if="${UIMAGE}" ibs=4 count=1 | hexdump -v -e '1/1 "%02X"'`
  25. [ '27051956' != "${MAGIC}" ] && { echo 'Not an uImage.' ; exit 1 ; }
  26. # extract data from uImage
  27. echo 'uImage recognized.'
  28. echo 'Extracting data...'
  29. DATAFILE='uImage.data'
  30. dd if="${UIMAGE}" of="${DATAFILE}" ibs=64 skip=1
  31. # check for ARM mach type ( xx 1C A0 E3 xx 10 81 E3 )
  32. # http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#d0e600
  33. echo 'Checking for ARM mach-type...'
  34. MAGIC=`dd if="${DATAFILE}" ibs=1 skip=1 count=3 | hexdump -v -e '1/1 "%02X"'`
  35. [ '1CA0E3' = "${MAGIC}" ] && {
  36. MAGIC=`dd if="${DATAFILE}" ibs=1 skip=5 count=3 | hexdump -v -e '1/1 "%02X"'`
  37. [ '1081E3' = "${MAGIC}" ] && {
  38. echo 'ARM mach-type header recognized.'
  39. echo 'Extracting mach-type header...'
  40. dd if="${DATAFILE}" of="uImage.mach-type" ibs=8 count=1
  41. ARCH=$(hexdump -v -e '1/1 "%02X "' uImage.mach-type); echo "The mach-type is: $ARCH"
  42. echo 'Stripping mach-type header...'
  43. TMPFILE='uImage.tmp'
  44. dd if="${DATAFILE}" of="${TMPFILE}" ibs=8 skip=1
  45. rm -f "${DATAFILE}"
  46. mv "${TMPFILE}" "${DATAFILE}"
  47. }
  48. }
  49. # check for zImage, otherwise assume Image
  50. # http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#d0e309
  51. TMPFILE='Image'
  52. echo 'Checking for zImage...'
  53. MAGIC=`dd if="${DATAFILE}" ibs=4 skip=9 count=1 | hexdump -v -e '1/1 "%02X"'`
  54. [ '18286F01' = "${MAGIC}" ] && {
  55. START=`dd if="${DATAFILE}" ibs=4 skip=10 count=1 | hexdump -v -e '1/4 "%08X"'`
  56. END=`dd if="${DATAFILE}" ibs=4 skip=11 count=1 | hexdump -v -e '1/4 "%08X"'`
  57. #
  58. SIZE=$(( 0x${END} - 0x${START} ))
  59. #
  60. echo "zImage recognized with start 0x${START}, end 0x${END} and size ${SIZE}."
  61. TMPFILE='zImage'
  62. }
  63. mv "${DATAFILE}" "${TMPFILE}"
  64. echo ">>> ${UIMAGE} extracted to ${TMPFILE}"

comments powered by Disqus