forked from embeddedTS/linux-2.6.35.3-imx28
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_bootstream
executable file
·133 lines (112 loc) · 3.67 KB
/
install_bootstream
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#########################################
# out_byte args...
#
# this function writes the binary value to stdout of each argument in the order given
# i.e. out_byte 0 1 2 3 will echo "\x00\x01\x02\x03" to stdout (w/o terminating null )
PATH=$PATH:/sbin/
function out_byte(){
for val in $*
do
# echo -e "byte=$val"
echo -en "\\x$(printf %02x $val)"
done
}
function out_u32_le()
{
for val32 in $*
do
val=$(($val32))
b0=$((val % (2**8)))
val=$((val / (2**8)))
b1=$((val % (2**8)))
val=$((val / (2**8)))
b2=$((val % (2**8)))
val=$((val / (2**8)))
b3=$((val % (2**8)))
### Keep around for debug/verbose output
# printf "$val32 ==> %02x%02x%02x%02x\n" $b0 $b1 $b2 $b3
### Output the bytes in binary form
#
out_byte $b0 $b1 $b2 $b3
done
}
function out_bcb ()
{
signature=0x00112233
primary_tag=$1
secondary_tag=$2
num_bsb=$3
out_u32_le signature primary_tag secondary_tag num_bsb
}
# usage: out_bsb tag base_sector
# where base_sector is relative to partition
# i.e. if partition starts on lba 63 & first boot stream, base_sector = 1, not 64
# This function will automatically compute the absolute base sector.
function out_bsb
{
abs_sector=$(($2 + $base_sector))
# unused0
out_u32_le 0
# unused1
out_u32_le 0
# tag boot stream tag
out_u32_le $1
# boot stream base sector (absolute)
out_u32_le $abs_sector
# unused2
out_u32_le 0
}
# Usage: mk_hdr <base_sector> <num_sb_files>
#
# where
#
# <base_sector> is the first sector _of the boot stream partition (i.e. /sd#2 or /sd#3, etc)
# <num_sb_files> is the # of boot stream blocks (currently only 1 supported)
#[ $1 = ] && { echo -e " error - boot partition start sector missing" ; exit };
#[ $2 = ] && { echo -e " error - # of bootable images in .sb file missing" ; exit };
# Future usage: make_boot <dev_partition> <sb_file_tag,sb_sector_offset> <sb_file_tag2, base_addr2> ...
#
# Where base sector comes from MBR, and sb_sector_offset is an offset from start of boot-partition, not absolute sector.
function mk_hdr() {
base_sector=$1
numbootstreams=$2
primary=0
secondary=0
###############################
# Send header output to std out
###############################
# Output boot stream signature & info
# out_u32_le signature primary secondary numbootstreams
out_bcb primary secondary numbootstreams
# Output .sb starting sector info
# out_u32_le unused0 unused1 tag base_sector unused2
out_bsb primary 1
# Output bsb for sb #2
#out_bsb tag_[p|s] base_sector_2
# Output bsb for sb #n
# out_bsb tag_[p|s] base_sector_n
#
}
if [ $# -ne 3 ] ; then
echo "Usage: $0 <bootstream> <device> <partition>"
echo "Where <bootstream is name of .sb file to use, <device> is name of device, i.e. sda, sdb, mmcblk0, etc."
echo "<partition> is the partition to load the bootstream on to"
exit 1
fi
if [ ! -e /dev/$2$3 ] ; then
echo "Error: Requested partition does not exist"
exit 1
fi
if [ `sudo fdisk -lu /dev/$2 | awk 'BEGIN{nores=1;} $5==53 { print $1; nores=0; } END{if (nores) print "Err";}'` != "/dev/$2$3" ] ; then
echo "Error: requested partition /dev/$2$3 does not have ID 53"
echo "Please make sure requested partition has the correct datatype"
exit 1
fi
echo -e "\nInstalling boot stream $1 on /dev/$2$3..."
mk_hdr `sudo fdisk -lu /dev/$2 | awk '$5==53 {print $2}'` 1 > temp.bin
sudo dd if=temp.bin of=/dev/$2$3 ibs=512 conv=sync
sudo dd if=$1 of=/dev/$2$3 ibs=512 obs=512 seek=1 conv=sync
sync
rm temp.bin
echo -e "...finished installing boot stream on $2$3.\n"