wrapper 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/sh
  2. # Copyright (C) 2006 Paul Mackerras, IBM Corporation <paulus@samba.org>
  3. # This program may be used under the terms of version 2 of the GNU
  4. # General Public License.
  5. # This script takes a kernel binary and optionally an initrd image
  6. # and/or a device-tree blob, and creates a bootable zImage for a
  7. # given platform.
  8. # Options:
  9. # -o zImage specify output file
  10. # -p platform specify platform (links in $platform.o)
  11. # -i initrd specify initrd file
  12. # -d devtree specify device-tree blob
  13. # -s tree.dts specify device-tree source file (needs dtc installed)
  14. # -c cache $kernel.strip.gz (use if present & newer, else make)
  15. # -C prefix specify command prefix for cross-building tools
  16. # (strip, objcopy, ld)
  17. # -D dir specify directory containing data files used by script
  18. # (default ./arch/powerpc/boot)
  19. # -W dir specify working directory for temporary files (default .)
  20. # defaults
  21. kernel=
  22. ofile=zImage
  23. platform=of
  24. initrd=
  25. dtb=
  26. dts=
  27. cacheit=
  28. # cross-compilation prefix
  29. CROSS=
  30. # directory for object and other files used by this script
  31. object=arch/powerpc/boot
  32. # directory for working files
  33. tmpdir=.
  34. usage() {
  35. echo 'Usage: wrapper [-o output] [-p platform] [-i initrd]' >&2
  36. echo ' [-d devtree] [-s tree.dts] [-c] [-C cross-prefix]' >&2
  37. echo ' [-D datadir] [-W workingdir] [vmlinux]' >&2
  38. exit 1
  39. }
  40. while [ "$#" -gt 0 ]; do
  41. case "$1" in
  42. -o)
  43. shift
  44. [ "$#" -gt 0 ] || usage
  45. ofile="$1"
  46. ;;
  47. -p)
  48. shift
  49. [ "$#" -gt 0 ] || usage
  50. platform="$1"
  51. ;;
  52. -i)
  53. shift
  54. [ "$#" -gt 0 ] || usage
  55. initrd="$1"
  56. ;;
  57. -d)
  58. shift
  59. [ "$#" -gt 0 ] || usage
  60. dtb="$1"
  61. ;;
  62. -s)
  63. shift
  64. [ "$#" -gt 0 ] || usage
  65. dts="$1"
  66. ;;
  67. -c)
  68. cacheit=y
  69. ;;
  70. -C)
  71. shift
  72. [ "$#" -gt 0 ] || usage
  73. CROSS="$1"
  74. ;;
  75. -D)
  76. shift
  77. [ "$#" -gt 0 ] || usage
  78. object="$1"
  79. ;;
  80. -W)
  81. shift
  82. [ "$#" -gt 0 ] || usage
  83. tmpdir="$1"
  84. ;;
  85. -?)
  86. usage
  87. ;;
  88. *)
  89. [ -z "$kernel" ] || usage
  90. kernel="$1"
  91. ;;
  92. esac
  93. shift
  94. done
  95. if [ -n "$dts" ]; then
  96. if [ -z "$dtb" ]; then
  97. dtb="$platform.dtb"
  98. fi
  99. dtc -O dtb -o "$dtb" -b 0 -V 16 "$dts" || exit 1
  100. fi
  101. if [ -z "$kernel" ]; then
  102. kernel=vmlinux
  103. fi
  104. platformo=$object/"$platform".o
  105. lds=$object/zImage.lds
  106. ext=strip
  107. objflags=-S
  108. tmp=$tmpdir/zImage.$$.o
  109. ksection=.kernel:vmlinux.strip
  110. isection=.kernel:initrd
  111. case "$platform" in
  112. pmac|pseries|chrp)
  113. platformo=$object/of.o
  114. ;;
  115. pmaccoff)
  116. platformo=$object/of.o
  117. lds=$object/zImage.coff.lds
  118. ;;
  119. miboot|uboot)
  120. # miboot and U-boot want just the bare bits, not an ELF binary
  121. ext=bin
  122. objflags="-O binary"
  123. tmp="$ofile"
  124. ksection=image
  125. isection=initrd
  126. ;;
  127. esac
  128. vmz="$tmpdir/`basename \"$kernel\"`.$ext"
  129. if [ -z "$cacheit" -o ! -f "$vmz.gz" -o "$vmz.gz" -ot "$kernel" ]; then
  130. ${CROSS}objcopy $objflags "$kernel" "$vmz.$$"
  131. gzip -f -9 "$vmz.$$"
  132. if [ -n "$cacheit" ]; then
  133. mv -f "$vmz.$$.gz" "$vmz.gz"
  134. else
  135. vmz="$vmz.$$"
  136. fi
  137. fi
  138. case "$platform" in
  139. uboot)
  140. rm -f "$ofile"
  141. version=`${CROSS}strings "$kernel" | grep '^Linux version [-0-9.]' | \
  142. cut -d' ' -f3`
  143. if [ -n "$version" ]; then
  144. version="-n Linux-$version"
  145. fi
  146. mkimage -A ppc -O linux -T kernel -C gzip -a 00000000 -e 00000000 \
  147. $version -d "$vmz.gz" "$ofile"
  148. if [ -z "$cacheit" ]; then
  149. rm -f $vmz.gz
  150. fi
  151. exit 0
  152. ;;
  153. esac
  154. addsec() {
  155. ${CROSS}objcopy $4 $1 \
  156. --add-section=$3="$2" \
  157. --set-section-flags=$3=contents,alloc,load,readonly,data
  158. }
  159. addsec $tmp "$vmz.gz" $ksection $object/empty.o
  160. if [ -z "$cacheit" ]; then
  161. rm -f "$vmz.gz"
  162. fi
  163. if [ -n "$initrd" ]; then
  164. addsec $tmp "$initrd" $isection
  165. fi
  166. if [ -n "$dtb" ]; then
  167. addsec $tmp "$dtb" .kernel:dtb
  168. if [ -n "$dts" ]; then
  169. rm $dtb
  170. fi
  171. fi
  172. if [ "$platform" != "miboot" ]; then
  173. ${CROSS}ld -m elf32ppc -T $lds -o "$ofile" \
  174. $object/crt0.o $platformo $tmp $object/wrapper.a
  175. rm $tmp
  176. fi
  177. # post-processing needed for some platforms
  178. case "$platform" in
  179. pseries|chrp)
  180. $object/addnote "$ofile"
  181. ;;
  182. pmaccoff)
  183. ${CROSS}objcopy -O aixcoff-rs6000 --set-start 0x500000 "$ofile"
  184. $object/hack-coff "$ofile"
  185. ;;
  186. esac