-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmk_hdr.sh
executable file
·114 lines (88 loc) · 2.51 KB
/
mk_hdr.sh
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
#!/bin/bash
# Usage: make_boot <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.
#Script Vars
base_sector=$1
numbootstreams=$2
primary=0
secondary=0
#########################################
# 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 )
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
}
###############################
# 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
#