O_全志V3s_F1C100s与V3s汇总


O_嵌入式专题目录


网址备份

F1C100s

Base

切换到root

sudo -i

更新源

apt-get update

安装ssh服务器

apt-get install ssh

命令行输入观察ubuntu的ip

ifconfig 或 ip -a
没这个工具的话 apt-get install net-tools

交叉工具链

解压交叉工具链

tar -vxJf gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz

安装交叉工具链

sudo cp -r ./gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi /opt/

修改环境变量

  • 安装vim:
    sudo apt-get install vim
  • 使用vim编辑
    sudo vim /etc/bash.bashrc
  • 在文件末尾添加
    PATH="$PATH:/opt/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin"
  • 使路径生效
    source /etc/bash.bashrc
  • 测试
    arm-linux-gnueabi-gcc -v

u-boot

安装git工具

sudo apt-get install git

克隆u-boot

git clone https://github.com/Lichee-Pi/u-boot.git
cd u-boot

查看分支

git branch -a

切换到 Nano 分支

git checkout nano-v2018.01

安装make

sudo apt install make

使用nano配置

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- licheepi_nano_spiflash_defconfig

此处告知make采用arm-linux-gnueabi下的所有交叉编译工具,目标架构为Arm,设定各项默认配置为 nano 的spiflash支持版,若不带spi-flash的板子,请换成 licheepi_nano_defconfig。

进行可视化配置

make ARCH=arm menuconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
ARM architecture  --->
[*]Enable graphical uboot console on HDMI, LCD or VGA
//分辨率:800*480
(x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0) LCD panel timing details
//分辨率:480*272
(x:480,y:272,depth:18,pclk_khz:10000,le:42,ri:8,up:11,lo:4,hs:1,vs:1,sync:3,vmode:0) LCD panel timing details
//分辨率:480*320
(x:480,y:320,depth:18,pclk_khz:10000,le:42,ri:8,up:11,lo:4,hs:1,vs:1,sync:3,vmode:0) LCD panel timing details
(1) LCD panel display clock phase (NEW)
() LCD panel power enable pin (NEW)
() LCD panel reset pin (NEW)
() LCD panel backlight enable pin(NEW)
() LCD panel backlight pwm pin

开始编译

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4
如果你的CPU支持8线程,则-j4可以修改为-j8,提高编译速度。编译完成后,可一看到目录下多了一堆以u-boot带头的文件,我们只需取 u-boot-sunxi-with-spl.bin 即可。

uboot默认终端串口为uart0。


  • 错误
    recipe for target ‘scripts/basic/fixdep’ failed
    /bin/sh: 1: cc: not found
    curses.h not found
    sudo apt-get install libncurses5-dev
    sudo apt-get install gcc
  • 错误
    recipe for target ‘scripts/dtc’ failed
    recipe for target ‘scripts’ failed
    sudo apt-get install device-tree-compiler
    sudo apt-get install libncurses5-dev libncursesw5-dev
    sudo apt-get install swig python-dev python3-dev

u-boot传递环境变量参数

在uboot环境变量里面需要设置内核和设备树的加载地址,使用boot.scr可以直接传递这些参数。

boot.scr是由boot.cmd使用mkimage工具生成的。boot.scr放在TF卡第一分区。
mkimage工具在uboot/tools文件夹下。

boot.cmd
  • 在uboot根目录下新建
    vim boot.cmd

  • 写入以下内容

    1
    2
    3
    4
    setenv bootargs console=tty0 console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 rw
    load mmc 0:1 0x80C00000 suniv-f1c100s-licheepi-nano.dtb
    load mmc 0:1 0x80008000 zImage
    bootz 0x80008000 - 0x80C00000

第一行setenv命令,设定了变量bootargs(启动参数)为:通过tty0和ttyS0串口输出启动信息;启动失败延迟5秒重启,根文件在TF卡的第二分区,可读写;
第二行指定了从TF中将设备树的dtb文件加载到0x80C00000的位置(地址参考自官方SDK)
第三行指定了将压缩后的内核zImage加载到0x80008000的位置
第四行为从加载地址启动内核的命令

mkimage
  • 该工具在uboot/tools文件夹下,在uboot根目录下输入以下命令拷贝到用户文件夹下,方便以后可以直接使用
    sudo cp ./tools/mkimage /usr/local/bin/mkimage

  • 使用以下命令生成boot.scr,然后将其放入第一分区
    mkimage -C none -A arm -T script -d boot.cmd boot.scr

1
2
3
4
5
6
7
8
9
root@ubuntu:~/f1c100s/u-boot# ./tools/mkimage -C none -A arm -T script -d boot.cmd boot.scr
Image Name:
Created: Tue Feb 23 16:08:09 2021
Image Type: ARM Linux Script (uncompressed)
Data Size: 216 Bytes = 0.21 KiB = 0.00 MiB
Load Address: 00000000
Entry Point: 00000000
Contents:
Image 0: 208 Bytes = 0.20 KiB = 0.00 MiB
  • ttyS1串口输出启动信息
    1
    2
    3
    4
    setenv bootargs console=tty1 console=ttyS1,115200 panic=5 rootwait root=/dev/mmcblk0p2 rw
    load mmc 0:1 0x80C00000 suniv-f1c100s-licheepi-nano.dtb
    load mmc 0:1 0x80008000 zImage
    bootz 0x80008000 - 0x80C00000

uboot的文件结构

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
.
├── api //封装一些平台无关的操作,如字符串打印,显示,网络,内存
├── arch //以平台架构区分
│ ├──arm
│ │ └──cpu
│ │ │ └──arm926ejs
│ │ │ │ └──sunxi //cpu相关的一些操作,如定时器读取
│ │ │ │ │ └──u-boot-spl.lds //spl的放置方法
│ │ └──dts
│ │ │ └──suniv-f1c100s-licheepi-nano.dts // f1c100s芯片的一些配置
│ │ │ └──suniv-f1c100s-licheepi-nano.dtb
│ │ │ └──suniv-f1c100s.dtsi
│ │ │ └──suniv.dtsi
│ │ └──lib //一些库文件
│ │ └──mach-sunxi
│ │ │ └──board.c //board_init_f
│ │ │ └──dram_sun4i.c //ddr的操作,复位,时钟,延时,odt,etc.
│ │ │ └──dram_helpers.c //ddr的设置及读写测试
├── board
│ ├──sunxi
│ │ └──board.c //sunxi_board_init 入口
│ │ └──dram_suniv.c //DRAM的一些默认参数
├── cmd //Uboot命令行的一些命令
├── common //含spl
├── configs //menuconfig里的默认配置,比如各类驱动适配
│ ├── licheepi_nano_defconfig
│ ├── licheepi_nano_spiflash_defconfig
├── disk //硬盘分区的驱动
├── doc
├── drivers //外设驱动
├── dts
├── examples
├── fs //多种文件系统
├── include
│ ├──configs
│ │ └──sunxi_common.h //预配置的参数,如串口号等
│ │ └──suniv.h
├── lib //加密压缩等算法
├── net //nfs,tftp等网络协议
├── post
├── scripts

linux

git clone https://github.com/Icenowy/linux.git

  • git拉取有时速度很慢,建议做如下配置:
    sudo vim /etc/hosts
    添加下面两行:
    140.82.113.3 github.com
    151.101.73.194 github.global.ssl.fastly.net
    可自行通过dns检测网站检测github.global.ssl.fastly.net,更换为更快的ip地址。

  • 完整拉取linux极大,建议只拉取单层分支,减少等待时间:
    git clone --depth=1 -b f1c100s-480272lcd-test https://github.com/Icenowy/linux.git
    git clone --depth=1 -b nano-5.2-tf https://github.com/Lichee-Pi/linux.git

  • 获取配置好的配置文件到linux源码的根目录(如果已存在.config,则需要替换)
    wget http://dl.sipeed.com/LICHEE/Nano/SDK/config
    cp config .config

  • 编译
    make ARCH=arm menuconfig
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j4
    生成的 zImage 在 arch ‣ arm ‣ boot 目录下;将其放入第一分区。
    生成的设备树suniv-f1c100s-licheepi-nano.dtb在 arch ‣ arm ‣ boot ‣ dts目录下;将其放入第一分区。

  • 错误
    /bin/sh: 1: flex: not found
    sudo apt-get install flex
    /bin/sh: 1: bison: not found
    sudo apt-get install bison

rootfs

安装依赖

apt-get install linux-headers-$(uname -r)

使用buildroot编译根文件系统

  • 获取buildroot源码
    wget https://buildroot.org/downloads/buildroot-2017.08.tar.gz
    tar xvf buildroot-2017.08.tar.gz
    cd buildroot-2017.08/

  • 配置bulidroot
    下载默认配置文件 buildroot.config
    wget https://fdvad021asfd8q.oss-cn-hangzhou.aliyuncs.com/migrate/buildroot.config
    复制一个并重命名:
    cp buildroot.config .config
    make menuconfig

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Target options  --->

    Target Architecture Variant (arm926t) ---> // arm926ejs架构
    [ ] Enable VFP extension support // Nano 没有 VFP单元,勾选会导致某些应用无法运行
    Target ABI (EABI) --->
    Floating point strategy (Soft float) ---> // 软浮点

    System configuration --->

    (Lichee Pi) System hostname // hostname
    (licheepi) Root password // 默认账户为root 密码为licheepi
    [*] remount root filesystem read-write during boot // 启动时重新挂在文件系统使其可读写
    */

下载依赖工具包

https://pan.baidu.com/s/1_tBdX9K7fOkH9JdXZ_MdiQ
  下载完之后,解压后复制到”buildroot-2017.08/dl/“下,没有dl文件夹可自行创建。将目录 A 下的所有文件复制到新目录 B 下:
cp -r /mnt/hgfs/E/ATY/Projects/Library/Development/Allwinnertech/Nano_F1c100s/dl/ /root/f1c100s/buildroot-2017.08/
  也可以不下载此工具包,但是buildroot自动更具需求下载这些工具包也许很慢。

rm -r dir 将目录及以下之档案亦逐一删除

编译

make

  • 错误
    make[2]: g++: Command not found
  • 安装G++工具:
    sudo apt-get install g++
    install the libc6-i386,lib32stdc++6, and lib32z1 packages

若第一次编译失败,make clean再次make编译。

编译完成的镜像包在 buildroot-2017.08 ‣ output ‣images ‣ rootfs.tar(大小98.1MB)。

查看rootfs文件的大小

ls -l output/images/rootfs.tar

将镜像包复制到第二分区后,解压即可

sudo umount /dev/sdX2
sudo mount /dev/sdX2 /mnt
sudo cp ./rootfs.tar /mnt/
sudo tar -xf /mnt/rootfs.tar -C mnt/
sudo rm /mnt/rootfs.tar
sync
sudo umount /dev/sdX2

另:检查 rootfs文件下的 /etc/inittab 是否已有以下声明
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 # GENERIC_SERIAL // 串口登录使能


buildroot默认终端串口为uart0

sunxi-tools

git clone -b f1c100s-spiflash https://github.com/Icenowy/sunxi-tools.git
cd sunxi-tools
make && sudo make install

  • 错误
    /bin/sh: 1: pkg-config: not found
    sudo apt install pkg-config
  • 错误
    fel_lib.c:26:20: fatal error: libusb.h: No such file or directory
    sudo apt-get install libusb-1.0-0-dev
  • 错误
    fatal error: zlib.h: No such file or directory
    sudo apt-get install zlib1g-dev

分区

sudo fdisk -l 首先查看电脑上已插入的TF卡的设备号
sudo umount /dev/sdXx 若自动挂载了TF设备,请先卸载
sudo fdisk /dev/sdX 进行分区操作
若已存分区即按 d 删除各个分区
通过 n 新建分区,第一分区暂且申请为32M(足够大了…),剩下的空间都给第二分区
w 保存写入并退出
sudo mkfs.vfat /dev/sdX1 将第一分区格式化成FAT
sudo mkfs.ext4 /dev/sdX2 将第一分区格式化成EXT4

下载

fel

  • 确认有无成功进入fel模式
    sudo sunxi-fel ver

  • 1.以 uboot file-with-spl形式进行(单次运行,测试时个人推荐)
    sunxi-fel uboot /your/path/to/u-boot-sunxi-with-spl.bin # 请自行修改到本机地址

  • 2.烧进 spi-flash (开机自启)
    sunxi-fel -p spiflash-write 0 /your/path/to/u-boot-sunxi-with-spl.bin
    note: 重新烧录或重进fel模式时,请在上电时拉低SPI flash 的 CS引脚

sudo dd if=/path/to/your-dd-image of=/your/tf-card && sync
sudo dd if=/mnt/hgfs/E/ATY/Projects/Library/Development/Allwinnertech/Nano_F1c100s/Lichee\ Nano/IOS/Nano_tf_480272.dd of=/dev/sdb1 && sync

sh

write_all.sh — 为tf卡创建全套内容使用:write_all.sh /dev/sdX (sdX修改为tf设备号)
write_flash.sh — 为spi-flash写入全套内容
write_dd.sh — 以dd镜像的方式写入全套内容(规定了分区信息)(生成方式见下一节)
write_boot.sh — 向tf卡dd进Uboot
write_mkfs.sh — 单纯的为两个分区进行硬盘格式化
write_p1.sh — 单纯的向第一分区写入设备树内核等
write_p2.sh — 单纯的向第二分区写入rootfs
clear_partion.sh — 擦除分区表
write_partion.sh — 写入分区表
write_swap.sh — 增加swap

  镜像生成最简单的方法是借助tf卡,手动或使用脚本向tf写入完结构,再dd出来。能够判断镜像大小是否符合启动要求,且借助loop模拟创建设备,快速高效。生成的镜像在 ./image 目录下。

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
sh pack_tf_img.sh — 生成TF卡镜像
sh pack_flash_img.sh — 生成SPI-FLASH镜像
/*----------------------------------------------------------------------------*/
write_all.sh
#!/bin/sh
./clear_partion.sh && ./write_partion.sh && ./write_mkfs.sh && ./write_boot.sh && ./write_p1.sh && ./write_p2.sh
/*----------------------------------------------------------------------------*/
clear_partion.sh
#!/bin/sh
sudo fdisk /dev/sdb<<EOF
d
1
d
2
d
3
d
4
w
p
q
EOF
/*----------------------------------------------------------------------------*/
write_partion.sh
#!/bin/sh
sudo fdisk /dev/sdb <<EOF
n
p
1
+32M
n
p
2
p
w
q
EOF
/*----------------------------------------------------------------------------*/
write_mkfs.sh
#!/bin/sh
sudo mkfs.vfat /dev/sdb1
sudo mkfs.ext4 /dev/sdb2
/*----------------------------------------------------------------------------*/
write_boot.sh
#!/bin/sh
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8
/*----------------------------------------------------------------------------*/
write_p1.sh
#!/bin/sh
sudo mkdir mnt
sudo mount /dev/sdb1 mnt
sudo cp zImage mnt/
sudo cp suniv-f1c100s-licheepi-nano.dtb mnt/
sudo cp boot.scr mnt/
sync
sudo umount /dev/sdb1
echo "###write partion 1 ok!"
/*----------------------------------------------------------------------------*/
write_p2.sh
#!/bin/sh
sudo mount /dev/sdb2 mnt
time sudo tar -xvf rootfs.tar -C mnt
//sudo rm -rf mnt/lib/modules/*
//sudo time cp -rf lib/modules/3.4.104/ mnt/lib/modules/
sync
sudo umount /dev/sdb2
/*----------------------------------------------------------------------------*/

列出各种板子信息

bdinfo

常用Linux命令

使用tar压缩文件

tar -zcvf test.tar.gz ./test/
该命令表示压缩当前文件夹下的文件夹test,压缩后缀名为test.tar.gz

如果不需要压缩成gz,只需要后缀为tar格式的,那么输入如下命令:
tar -cvf test.tar ./test/

使用tar解压文件

tar -xzvf test.tar.gz
该命令表示把后缀为.tar.gz的文件解压到当前文件夹下。

如果压缩文件的后缀是.tar,没有gz,则使用命令:
tar -xvf test.tar

zip

  • zip
    zip -r myfile.zip ./*
    将当前目录下的所有文件和文件夹全部压缩成myfile.zip内联代码块文件,内联代码块-r表示递归压缩子目录下所有文件。

  • unzip
    unzip -o -d /home/sunny myfile.zip
    把myfile.zip文件解压到 /home/sunny/
    -o:不提示的情况下覆盖文件;
    -d:-d /home/sunny指明将文件解压缩到/home/sunny目录下。

  • 其他
    zip -d myfile.zip smart.txt
    删除压缩文件中smart.txt文件
    zip -m myfile.zip ./rpm_info.txt
    向压缩文件中myfile.zip中添加rpm_info.txt文件。

软件包卸载

  • 查看已安装的软件包列表
    dpkg --list

  • 卸载程序和所有配置文件
    sudo apt-get --purge remove <programname>

  • 只卸载程序,但保留配置文件
    sudo apt-get remove <programname>

Vim

命令模式:

用户刚刚启动 vi/vim,便进入了命令模式。

此状态下敲击键盘动作会被Vim识别为命令,而非输入字符。比如我们此时按下i,并不会输入一个字符,i被当作了一个命令。

以下是常用的几个命令:

i 切换到输入模式,以输入字符。
x 删除当前光标所在处的字符。
: 切换到底线命令模式,以在最底一行输入命令。
若想要编辑文本:启动Vim,进入了命令模式,按下i,切换到输入模式。(i a o)

命令模式只有一些最基本的命令,因此仍要依靠底线命令模式输入更多命令。

输入模式

在命令模式下按下i就进入了输入模式。

在输入模式中,可以使用以下按键:

字符按键以及Shift组合,输入字符
ENTER,回车键,换行
BACK SPACE,退格键,删除光标前一个字符
DEL,删除键,删除光标后一个字符
方向键,在文本中移动光标
HOME/END,移动光标到行首/行尾
Page Up/Page Down,上/下翻页
Insert,切换光标为输入/替换模式,光标将变成竖线/下划线
ESC,退出输入模式,切换到命令模式

底线命令模式

在命令模式下按下:(英文冒号)就进入了底线命令模式。

底线命令模式可以输入单个或多个字符的命令,可用的命令非常多。

在底线命令模式中,基本的命令有(已经省略了冒号):

q 退出程序
w 保存文件
按ESC键可随时退出底线命令模式。

root

给root用户设置密码
sudo passwd root
切换到root权限
su root
切换到普通用户
su xyx命令

换源

root的图形化文件管理器

sudo nautilus

fdisk

语法

fdisk(选项)(参数)

选项

-b<分区大小>:指定每个分区的大小;
-l:列出指定的外围设备的分区表状况;
-s<分区编号>:将指定的分区大小输出到标准输出上,单位为区块;
-u:搭配”-l”参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址;
-v:显示版本信息。

参数

设备文件:指定要进行分区或者显示分区的硬盘设备文件。

实例

  • 首先选择要进行操作的磁盘:

    1
    [root@localhost ~]# fdisk /dev/sdb
  • 输入m列出可以执行的命令:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    command (m for help): **m**
    Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    l list known partition types
    m print this menu
    n add a new partition
    o create a new empty DOS partition table
    p print the partition table
    q quit without saving changes
    s create a new empty Sun disklabel
    t change a partition's system id
    u change display/entry units
    v verify the partition table
    w write table to disk and exit
    x extra functionality (experts only)
  • 输入p列出磁盘目前的分区情况:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Command (m for help): p

    Disk /dev/sdb: 3221 MB, 3221225472 bytes
    255 heads, 63 sectors/track, 391 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdb1 1 1 8001 8e Linux LVM
    /dev/sdb2 2 26 200812+ 83 Linux
  • 输入d然后选择分区,删除现有分区:

    1
    2
    3
    4
    5
    Command (m for help): d
    Partition number (1-4): 1

    Command (m for help): d
    Selected partition 2
  • 查看分区情况,确认分区已经删除:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Command (m for help): print

    Disk /dev/sdb: 3221 MB, 3221225472 bytes
    255 heads, 63 sectors/track, 391 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System

    Command (m for help):
  • 输入n建立新的磁盘分区,首先建立两个主磁盘分区:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p //建立主分区 ----------- *注意*------------------------
    Partition number (1-4): 1 //分区号
    First cylinder (1-391, default 1): //分区起始位置
    Using default value 1
    last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区

    Command (m for help): n //再建立一个分区
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4): 2 //分区号为2
    First cylinder (101-391, default 101):
    Using default value 101
    Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M
  • 确认分区建立成功:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Command (m for help): p

    Disk /dev/sdb: 3221 MB, 3221225472 bytes
    255 heads, 63 sectors/track, 391 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdb1 1 100 803218+ 83 Linux
    /dev/sdb2 101 125 200812+ 83 Linux
  • 再建立一个逻辑分区:

    1
    2
    3
    4
    5
    6
    7
    8
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    e //选择扩展分区 ---------------------注意-------------------------
    Partition number (1-4): 3
    First cylinder (126-391, default 126):
    Using default value 391
  • 确认扩展分区建立成功:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Command (m for help): p

    Disk /dev/sdb: 3221 MB, 3221225472 bytes
    255 heads, 63 sectors/track, 391 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdb1 1 100 803218+ 83 Linux
    /dev/sdb2 101 125 200812+ 83 Linux
    /dev/sdb3 126 391 2136645 5 Extended
  • 在扩展分区上建立两个逻辑分区:

    1
    2
    3
    4
    5
    6
    7
    8
    Command (m for help): n
    Command action
    l logical (5 or over)
    p primary partition (1-4)
    l //选择逻辑分区 --------------------注意---------------------
    First cylinder (126-391, default 126):
    Using default value 126
    Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M
  • 建立第二个逻辑分区

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Command (m for help): n
    Command action
    l logical (5 or over)
    p primary partition (1-4)
    l
    First cylinder (176-391, default 176):
    Using default value 176
    Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
    Using default value 391
  • 确认逻辑分区建立成功:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Command (m for help): p

    Disk /dev/sdb: 3221 MB, 3221225472 bytes
    255 heads, 63 sectors/track, 391 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdb1 1 100 803218+ 83 Linux
    /dev/sdb2 101 125 200812+ 83 Linux
    /dev/sdb3 126 391 2136645 5 Extended
    /dev/sdb5 126 175 401593+ 83 Linux
    /dev/sdb6 176 391 1734988+ 83 Linux

    Command (m for help):

总结:

  • 一般情况下使用fidsk -l 查看磁盘使用情况
  • 使用fdisk /dev/***进行分区
  • 可以分为主分区p 也可以分为扩展分区e 但是逻辑分区没有L 暂时不纠结这个问题了。
  • 创建好分区后,p 打印 w写入 t修改类型

磁盘详情df

df -hl
df 命令是linux系统上以磁盘分区为单位来查看文件系统的命令,后面可以加上不同的参数来查看磁盘的剩余空间信息。

  • 显示格式:
    文件系统 容量 已用 可用 已用% 挂载点 
    Filesystem Size Used Avail Use% Mounted on
    /dev/hda2 45G 19G 24G 44% /
    /dev/hda1 494M 19M 450M 4% /boot
    /dev/hda6 4.9G 2.2G 2.5G 47% /home
    /dev/hda5 9.7G 2.9G 6.4G 31% /opt
    none 1009M 0 1009M 0% /dev/shm
    /dev/hda3 9.7G 7.2G 2.1G 78% /usr/local
    /dev/hdb2 75G 75G 0 100% /

以最后一行为例,其中,hdb2表示第二个硬盘的第二个分区,容量为75G,已用75G,可用0,已用100%,挂载点为根分区目录(/)。

  • 相关命令解释:

    df -hl 查看磁盘剩余空间
    df -h 查看每个根路径的分区大小
    du -sh [目录名] 返回该目录的大小
    du -sm [文件夹] 返回该文件夹总M数
    df --help 查看更多功能

  • 另外附一些其他命令:

    查看硬盘的分区 #sudo fdisk -l
    查看IDE硬盘信息 #sudo hdparm -i /dev/hda
    查看STAT硬盘信息 #sudo hdparm -I /dev/sda 或 #sudo apt-get install blktool #sudo blktool /dev/sda id
    查看硬盘剩余空间 #df -h #df -H
    查看目录占用空间 #du -hs 目录名
    优盘没法卸载 #sync fuser -km /media/usbdisk

VM安装VMtools灰色不可用

设置CD/DVD及软盘为自动检测

xshell串口文件传输

rz 上传
sz 下载

xshell通过ssh方式连接Linux机器

  1. cd /etc/ssh 进入ssh目录下,然后ls列出文件列表,我的如下:
    moduli ssh_config sshd_config ssh_host_rsa_key ssh_host_rsa_key.pub ssh_import_id
    ssh_config是ssh的配置,sshd_config是ssh服务端的配置

  2. 如果第一步没有ssh_host_rsa_key、ssh_host_rsa_key.pub 这两个文件,可以通过第3步生成。我的一开始就没有。

  3. 生成第2步的两个文件,如果有了就跳过这一步。
    命令行输入 sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key 然后一直回车即可。

  4. 编辑配置 sshd_config 配置文件,/etc/ssh目录下命令行输入 sudo vi sshd_config ,修改如下:
    1)HostKeys for protocol version 2 只保留箭头的 HostKey /etc/ssh/ssh_host_rsa_key,其他的注解掉,因为我们只生成了箭头的那个key。
    2)注解掉禁止密码登陆 porhibit--password,添加允许密码登陆 PermitRootLogin yes,这样xshell等第三方工具接口通过账号和密码以ssh方式连接。
    3)确保 PasswordAuthentication 为yes,默认情况也是yes就不用管。

  5. 然后按下esc键,输入:wq保存退出了

  6. 输入 sudo /etc/init.d/ssh restart 重启ssh服务即可。然后可以通过输入 service ssh status 查看到sshd正在运行。

V3s

交叉工具链

1
2
3
4
5
6
7
8
9
//wget https://releases.linaro.org/components/toolchain/binaries/latest/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz
wget https://releases.linaro.org/components/toolchain/binaries/6.3-2017.05/arm-linux-gnueabihf/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz
tar xvf gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf.tar.xz
mv gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf /opt/
vim /etc/bash.bashrc
# add: PATH="$PATH:/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin"
source /etc/bash.bashrc
arm-linux-gnueabihf-gcc -v
sudo apt-get install device-tree-compiler

u-boot

1
2
3
4
5
6
7
git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-current
#or git clone https://github.com/Lichee-Pi/u-boot.git -b v3s-spi-experimental
cd u-boot
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_800x480LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_480x272LCD_defconfig
#or make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LicheePi_Zero_defconfig
make ARCH=arm menuconfig

修改 include/configs/sun8i.h, 使u-boot可以直接从tf卡启动

1
2
3
4
5
6
#define CONFIG_BOOTCOMMAND   "setenv bootm_boot_mode sec; " \
"load mmc 0:1 0x41000000 zImage; " \
"load mmc 0:1 0x41800000 sun8i-v3s-licheepi-zero.dtb; " \
"bootz 0x41000000 - 0x41800000;"

#define CONFIG_BOOTARGS "console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 earlyprintk rw vt.global_cursor_default=0"

1
2
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4
//time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- 2>&1 | tee build.log

编译完成后,在当前目录下生成了u-boot-sunxi-with-spl.bin,可以烧录到8K偏移处启动。

  • uboot中的目录结构
    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
    ├── api                存放uboot提供的API接口函数
    ├── arch 平台相关的部分我们只需要关心这个目录下的ARM文件夹
    │ ├──arm
    │ │ └──cpu
    │ │ │ └──armv7
    │ │ └──dts
    │ │ │ └──*.dts 存放设备的dts,也就是设备配置相关的引脚信息
    ├── board 对于不同的平台的开发板对应的代码
    ├── cmd 顾名思义,大部分的命令的实现都在这个文件夹下面。
    ├── common 公共的代码
    ├── configs 各个板子的对应的配置文件都在里面,我们的Lichee配置也在里面
    ├── disk 对磁盘的一些操作都在这个文件夹里面,例如分区等。
    ├── doc 参考文档,这里面有很多跟平台等相关的使用文档。
    ├── drivers 各式各样的驱动文件都在这里面
    ├── dts 一种树形结构(device tree)这个应该是uboot新的语法
    ├── examples 官方给出的一些样例程序
    ├── fs 文件系统,uboot会用到的一些文件系统
    ├── include 头文件,所有的头文件都在这个文件夹下面
    ├── lib 一些常用的库文件在这个文件夹下面
    ├── Licenses 这个其实跟编译无关了,就是一些license的声明
    ├── net 网络相关的,需要用的小型网络协议栈
    ├── post 上电自检程序
    ├── scripts 编译脚本和Makefile文件
    ├── spl second program loader,即相当于二级uboot启动。
    ├── test 小型的单元测试程序。
    └── tools 里面有很多uboot常用的工具。

linux

  • 获取Linux源码(zero-4.13.y分支对网卡支持比较好)
    git clone https://github.com/Lichee-Pi/linux.git -b zero-4.13.y

  • 生成荔枝派Zero 默认配置文件
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- licheepi_zero_defconfig

  • 设备树文件(默认不需要修改)
    arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts
    make ARCH=arm menuconfig

  • 编译内核
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4

  • 编译设备树
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
    arch/arm/boot/zImage
    arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dtb

1
2
3
4
5
6
git clone https://github.com/Lichee-Pi/linux.git
make ARCH=arm licheepi_zero_defconfig
make ARCH=arm menuconfig #add bluethooth, etc.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 INSTALL_MOD_PATH=out modules_install

编译完成后,zImage在arch/arm/boot/下,驱动模块在out/下

make menuconfig一定要确认参数保存到了.config文件!!!!!!!!!!!!!!!!

  • 主线linux5.11
    fatal error: gmp.h: No such file or directory
    sudo apt-get install libgmp3-dev
    fatal error: mpc.h: No such file or directory
    sudo apt-get install libmpc-dev
    sudo apt-get install libcgal-dev

rtl8723bs网卡

  • rtl8723bs.sh

    1
    2
    3
    4
    5
    #!/bin/sh
    # Add
    mkdir /lib/firmware
    mkdir /lib/firmware/rtlwifi
    cp /root/ls_files/rtl8723bs_nic.bin /lib/firmware/rtlwifi
  • wpa_supplicant.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    ctrl_interface=/var/run/wpa_supplicant
    ctrl_interface_group=0
    ap_scan=1
    network={
    ssid="ESPJ"
    scan_ssid=1
    key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
    pairwise=TKIP CCMP
    group=CCMP TKIP WEP104 WEP40
    psk="00000000"
    priority=5
    }

    vi /etc/init.d/rcS
    if [ -e /root/ls_files/rtl8723bs.sh ]; then
    /root/ls_files/rtl8723bs.sh
    fi
  • buildroot

    1
    2
    3
    4
    5
    6
    -> make menuconfig
    -> Target packages -> Networking applications

    选中(全部子项)
    wireless tools
    wpa_supplicant
1
2
3
4
5
6
7
insmod /root/ls_files/r8723bs.ko
# Opne wifi
ifconfig wlan0 up
# Search wifi
wpa_supplicant -B -d -i wlan0 -c /root/ls_files/wpa_supplicant.conf
# Connect wifi
udhcpc -i wlan0

Camera

gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-h264, width=800, height=600, framerate=25/1' ! queue ! h264parse ! flvmux ! rtmpsink location='rtmp://192.168.1.102/live'

  • 视频录制:
    ffmpeg -f video4linux2 -s 800x600 -r 30 -i /dev/video0 test.avi
  • 拍摄照片:
    fswebcam -S 20 -d /dev/video0 -p UYVY -r 800x600 --dumpframe dump.bin fswebcam.jpg
    fswebcam -S 1 -d /dev/video0 -p YUYV -r 800x600 tt01.jpg
  • 摄像头spitft
    arch/arm/boot/dts/sun8i_v3s.dtsi
    sun8i-v3s-licheepi-zero.dts

  • st7735屏幕spitft
    arch/arm/boot/dts/sun8i-v3s-licheepi-zero-spitft.dts
    arch/arm/boot/dts/Makefile

SPI屏 zero
3v3 3v3
GND GND
DC PWM1
RST 3v3
CS CS
CLK CLK
MISO MISO
MOSI MOSI

使用OV2640时,原驱动拍出来的照片很暗,需要将0x3C寄存器的值调整为0xEF。

屏幕分辨率

尺寸 (宽 x 高) 代号 全拼 尺寸比例
128 x 96 subQCIF 4:3
176 X 144 QCIF 11:9
320 x 200 CGA Color-Graphics-Adapter 8:5
320 x 240 Quarter-VGA 4:3
352 x 288 CIF 11:9
640 x 350 EGA Extended-Graphics-Adapter 64:35
640 x 480 VGA Video-Graphics-Array 4:3
800 x 600 SVGA Super-Video-Graphics-Array 4:3
1024 x 768 XGA eXtended-VGA 4:3
1280 x 768 XGA-W 15:9
1280 x 960 QVGA Quad-VGA 4:3
1280 x 1024 SXGA Super-eXtended-VGA 5:4
1400 x 1050 SXGA+ Super-eXtended-VGA-plu 4:3
1600 x 1024 SXGA-W 25:16
1600 x 1200 UGA Ultra-VGA 4:3
1920 x 1080 HDTV High-Definition-TV 16:9
1900 x 1200 UXGA Ultra-eXtended-VGA 19:12
1920 x 1200 UXGA-W 8:5
2048 x 1536 QXGA Quad-eXtended-VGA 4:3
2560 x 2048 QSXGA Quad-Super-eXtended-VGA 5:4
3200 x 2400 QUXGA Quad-Ultra-eXtended-VGA 4:3
3840 x 2400 QUXGA-W 8:5

文档备份