Blame view

buildroot/buildroot-2016.08.1/board/freescale/imx28evk/create-boot-sd.sh 1.94 KB
6b13f685e   김민수   BSP 최초 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  #!/bin/sh
  
  set -u
  set -e
  
  PROGNAME=$(basename $0)
  
  usage()
  {
      echo "Create an SD card that boots on an i.MX28 EVK board."
      echo
      echo "Note: all data on the the card will be completely deleted!"
      echo "Use with care!"
      echo "Superuser permissions may be required to write to the device."
      echo
      echo "Usage: ${PROGNAME} <sd_block_device>"
      echo "Arguments:"
      echo "  <sd_block_device>     The device to be written to"
      echo
      echo "Example: ${PROGNAME} /dev/mmcblk0"
      echo
  }
  
  if [ $# -ne 1 ]; then
      usage
      exit 1
  fi
  
  if [ $(id -u) -ne 0 ]; then
      echo "${PROGNAME} must be run as root"
      exit 1
  fi
  
  DEV=${1}
  
  # The partition name prefix depends on the device name:
  # - /dev/sde -> /dev/sde1
  # - /dev/mmcblk0 -> /dev/mmcblk0p1
  if echo ${DEV}|grep -q mmcblk ; then
      PART="p"
  else
      PART=""
  fi
  
  PART1=${DEV}${PART}1
  PART2=${DEV}${PART}2
  PART3=${DEV}${PART}3
  
  # Unmount the partitions if mounted
  umount ${PART1} || true
  umount ${PART2} || true
  umount ${PART3} || true
  
  # First, clear the card
  dd if=/dev/zero of=${DEV} bs=1M count=20
  
  sync
  
  # Partition the card.
  # SD layout for i.MX28 boot:
  # - Special partition type 53 at sector 2048, containing an SD-SB-encapsulated u-boot
  # - FAT partition containing zImage
  # - ext2/3 partition formatted as ext2 or ext3, containing the root filesystem.
  sfdisk --force -u S ${DEV} <<EOF
  2048,2000,53
  4048,16000,b
  20048,,L
  EOF
  
  sync
  
  # Copy the bootloader at offset 2048
  # (We need to skip the partition table in the .sd, too.)
  dd if=output/images/u-boot.sd of=${DEV}1 bs=1M
  
  # Prepare a temp dir for mounting partitions
  TMPDIR=$(mktemp -d)
   
  # FAT partition: kernel
  mkfs.vfat ${PART2}
  mount ${PART2} ${TMPDIR}
  cp output/images/*Image ${TMPDIR}/
  cp output/images/*.dtb  ${TMPDIR}/ || true
  sync
  umount ${TMPDIR}
  
  # ext2 partition: root filesystem
  mkfs.ext2 ${PART3}
  mount ${PART3} ${TMPDIR}
  tar -C ${TMPDIR}/ -xf output/images/rootfs.tar
  sync
  umount ${TMPDIR}
  
  # Cleanup
  rmdir ${TMPDIR}
  sync
  echo Done