当前位置: 首页 > news >正文

OK335x mksd.sh hacking

#! /bin/sh
# mk3PartSDCard.sh v0.3
# Licensed under terms of GPLv2

# 参考文档:
#     1. sfidsk创建可启动分区问题
#         http://segmentfault.com/a/1190000002493628
#     2. sfdisk 中文手册
#         http://blog.csdn.net/hnmsky/article/details/7650964
#     3. linux sfdisk partition
#         http://blog.csdn.net/shell_albert/article/details/8425530
#     4. How to Make 3 Partition SD Card
#         http://processors.wiki.ti.com/index.php/How_to_Make_3_Partition_SD_Card

if [ $# -ne 1 ]; then
    echo "USAGE:"
    echo "    $0 <device node>"
    exit -1;
fi

# 获取SD卡设备节点,并擦除分区表
DRIVE=$1
dd if=/dev/zero of=$DRIVE bs=1024 count=1024

# 获取SD卡大小,并在terminal中显示字节大小
SIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
echo DISK SIZE - $SIZE bytes

# 计算磁柱数
# 每一个柱面的大小为255*63*512=8,225,280 Bytes
CYLINDERS=`echo $SIZE/255/63/512 | bc`

# Usage:
#  sfdisk [options] <device> [...]
# 
# Options:
#  -s, --show-size           list size of a partition
#  -c, --id                  change or print partition Id
#      --change-id           change Id
#      --print-id            print Id
#  -l, --list                list partitions of each device
#  -d, --dump                idem, but in a format suitable for later input
#  -i, --increment           number cylinders etc. from 1 instead of from 0
#  -u, --unit <letter>       units to be used; <letter> can be one of
#                              S (sectors), C (cylinders), B (blocks), or M (MB)
#  -1, --one-only            reserved option that does nothing currently
#  -T, --list-types          list the known partition types
#  -D, --DOS                 for DOS-compatibility: waste a little space
#  -E, --DOS-extended        DOS extended partition compatibility
#  -R, --re-read             make the kernel reread the partition table
#  -N <number>               change only the partition with this <number>
#  -n                        do not actually write to disk
#  -O <file>                 save the sectors that will be overwritten to <file>
#  -I <file>                 restore sectors from <file>
#  -V, --verify              check that the listed partitions are reasonable
#  -v, --version             display version information and exit
#  -h, --help                display this help text and exit
# 
# Dangerous options:
#  -f, --force               disable all consistency checking
#      --no-reread           do not check whether the partition is in use
#  -q, --quiet               suppress warning messages
#  -L, --Linux               do not complain about things irrelevant for Linux
#  -g, --show-geometry       print the kernel's idea of the geometry
#  -G, --show-pt-geometry    print geometry guessed from the partition table
#  -A, --activate[=<device>] activate bootable flag
#  -U, --unhide[=<dev>]      set partition unhidden
#  -x, --show-extended       also list extended partitions in the output,
#                              or expect descriptors for them in the input
#      --leave-last          do not allocate the last cylinder
#      --IBM                 same as --leave-last
#      --in-order            partitions are in order
#      --not-in-order        partitions are not in order
#      --inside-outer        all logicals inside outermost extended
#      --not-inside-outer    not all logicals inside outermost extended
#      --nested              every partition is disjoint from all others
#      --chained             like nested, but extended partitions may lie outside
#      --onesector           partitions are mutually disjoint
# 
# Override the detected geometry using:
#  -C, --cylinders <number>  set the number of cylinders to use
#  -H, --heads <number>      set the number of heads to use
#  -S, --sectors <number>    set the number of sectors to use
#

# sfdisk的-D参数指定与DOS兼容,并自动在每个分区前预留空间,以存放MBR(Master Boot Record);
#
# <start>, <size>, <id>, <bootable> 
#
# bootable 可以指定为[*|-]格式,默认值是"-"也就是没有可引导标记。
# 这个标记仅对DOS有意义:DOS会给带有可引导标记的主分区分配 C: 盘符
#
# id 应该以无"0x"前缀的格式给出其十六进制值,或者[E|S|L]简写字母:
#     L(83)是默认值;
#     S(82,LINUX_SWAP);
#     E(5,扩展分区)。
# 
# 第一行分区描述,9,0x0C,* 自动分配起始柱面,数量为9,分区ID为0x0C(表示FAT32分区),<bootable>为*, 表示可启动分区。
# 第二行分区描述10,115,,- 同样自动分配起柱面,数量为115,其它为默认。
# 第三行分区描述126,,,- 同样自动分配起柱面,剩下所有的数量,其它为默认。
sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
,9,0x0C,*
10,115,,-
126,,,-
EOF

# 这里可以得到一张FAT32分区的SD卡,我有时候我们就只需要一张这样的卡
# sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
# ,,0x0C,*
# EOF

# 格式化各个分区,格式化完卸载对应的分区
mkfs.vfat -F 32 -n "boot" ${DRIVE}1
umount ${DRIVE}1
mkfs.ext3 -L "rootfs" ${DRIVE}2
umount ${DRIVE}2
mkfs.ext3 -L "START_HERE" ${DRIVE}3

 

相关文章:

  • c#获取url请求的返回值(转)
  • ios开发 xcode6以上安装Alcatraz管理插件
  • 部署与管理ZooKeeper
  • linux内核移植X86平台的例子
  • 【BZOJ】3526: [Poi2014]Card
  • 解决mysql查询中文乱码问题
  • js字符串 数组处理
  • Redhat编译php-5.2.9出现error dereferencing pointer to incomplete type
  • 推荐10个很棒的AngularJS学习指南
  • web -- Angularjs 笔记
  • 简单的5*5,五子棋小游戏
  • 教你上电脑课怎么摆脱老师的控制
  • HTML标签,CSS简介
  • (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
  • [转]Java中怎样判断一个字符串能否转成数字
  • 《微软的软件测试之道》成书始末、出版宣告、补充致谢名单及相关信息
  • CSS居中完全指南——构建CSS居中决策树
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • Java 23种设计模式 之单例模式 7种实现方式
  • JavaScript 基础知识 - 入门篇(一)
  • JS笔记四:作用域、变量(函数)提升
  • leetcode98. Validate Binary Search Tree
  • Phpstorm怎样批量删除空行?
  • Quartz初级教程
  • Yii源码解读-服务定位器(Service Locator)
  • 爱情 北京女病人
  • 浮动相关
  • 复杂数据处理
  • 官方新出的 Kotlin 扩展库 KTX,到底帮你干了什么?
  • ------- 计算机网络基础
  • 讲清楚之javascript作用域
  • 前端学习笔记之观察者模式
  • 三栏布局总结
  • 网页视频流m3u8/ts视频下载
  • 写给高年级小学生看的《Bash 指南》
  • 正则表达式
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • (C++17) optional的使用
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (独孤九剑)--文件系统
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (蓝桥杯每日一题)love
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • (转)Mysql的优化设置
  • *** 2003
  • .NET Core WebAPI中使用Log4net 日志级别分类并记录到数据库
  • .NET 将混合了多个不同平台(Windows Mac Linux)的文件 目录的路径格式化成同一个平台下的路径
  • .net网站发布-允许更新此预编译站点
  • .NET下ASPX编程的几个小问题
  • .Net中间语言BeforeFieldInit
  • .vimrc php,修改home目录下的.vimrc文件,vim配置php高亮显示
  • @Async注解的坑,小心
  • @AutoConfigurationPackage的使用
  • @cacheable 是否缓存成功_Spring Cache缓存注解