代码拉取完成,页面将自动刷新
#!/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 '$6==53 {print $1}'` != "/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 '$6==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"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。