在PICOBSD生成后有一个picobsd.bin
复制到软盘后,可以看到只有一个kernel文件
到底是如处生成如何加载的?
看看picobsd 就明白了,真不容易呀
fill_floppy_image() {
local blocks sectors dst
log “fill_floppy_image()”
dst=${c_mnt} # where to create the image /tmp/picobsd.xxxxxxxx
log “Preparing ${fd_size}kB floppy filesystem…”
# correct block and number of sectors according to size.
blocks=${fd_size}; sectors=18 判断软盘参数
if [ "${blocks}" = "1720" ]; then
blocks=1722 ; sectors=21
elif [ "${blocks}" = "1480" ]; then
blocks=1476 ;
fi
init_fs_image ${BUILDDIR}/${c_img} ${blocks} 创建磁盘映象文件
log “Labeling floppy image”
b2=${BUILDDIR}/boot2 # modified boot2 对当前文件系统 里的boot2文件进行处理
perl -pne ’s/\/boot\/loader/\/kernel\0\0\0\0\0/’ ${c_boot2} > ${b2}
把”/boot/loader/kernel “变为空? 输出到本地的boot2
# create a disklabel … 格式化什么 的
disklabel -Brw -b ${c_boot1} -s ${b2} ${l_vndev} auto || \
fail $? floppy_disklabel
# and copy partition c: into partition a: using some sed magic
disklabel ${l_vndev} | sed -e ‘/ c:/{p;s/c:/a:/;}’ | \
disklabel -R ${l_vndev} /dev/stdin
log “Newfs floppy image”
newfs -i ${fd_inodes} -m 0 -p 0 -o space -f 512 -b 4096 \
/dev/${l_vndev}a > /dev/null
log “Mounting floppy image”
mount /dev/${l_vndev}a ${dst}
(
cd ${BUILDDIR}
# $1 takes the offset of the MFS filesystem
计算MFS文件系统应当在核心内的偏移量
set `strings -at d kernel | grep “MFS Filesystem goes here”`
再向后8192字节,是boot2的长度?
mfs_ofs=$(($1 + 8192))
log “Preload kernel with file ${c_fs} at ${mfs_ofs}”
对产生的kernel进行编辑,加入更多的信息在里面
dd if=${c_fs} ibs=8192 iseek=1 of=kernel obs=${mfs_ofs} \
oseek=1 conv=notrunc
log “Compress with kgzip and copy to floppy image”
压缩核心数据包
kgzip -o kernel.gz kernel
cp -p kernel.gz ${dst}/kernel || fail $? no_space “copying kernel”
log “now transfer floppy tree if needed”
# now transfer the floppy tree. If it is already in mfs, dont bother.
if [ "${o_all_in_mfs}" != "yes" ] ; then
cp -Rp floppy.tree/* ${dst} || \
fail $? no_space “copying floppy tree”
fi
)
(log “Fixing permissions”; cd ${dst}; chown -R root *)
# rm -rf ${BUILDDIR}/floppy.tree || true # cleanup
df -ik ${dst} | colrm 70 > .build.reply
free_vnode
rm -rf ${dst}
rm ${BUILDDIR}/kernel.gz ${BUILDDIR}/${c_fs}
}