210开发板

=========

手上有两块210开发板,15年和16年分别购买的,一块是友善之臂Smart210,一块是九鼎X210V3s.
很早以前玩的时候,还能从NoOS的裸机程序,到完整的BootUp,Linux和Android都能编译安装运行。
现在Android由于版本(JDK、make等)的问题,Android版本只有2.3和4.0,需要重新搭建环境,意义不大。暂且搁置。
Linux,当初提供的是Kernel 2.6,并且已经找不到源码了,网上有3.10的别人移植好的内核源码,一切从头开始!
几乎所有资料都要从网络上重新找。

Smart210_Linux_BSP

安装Uboot通过tftp加载kernel,再挂载NFS的方式。

准备跑kernel 2.6,装个老的

对友善之臂的,提供了一个Supperboot的bootloader,将
整个images目录拷贝到SD卡中

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/11/11     10:06                Android
d-----       2020/11/11     10:06                Android2.3.1
d-----       2020/11/11     10:06                Linux
d-----       2020/11/11     10:06                WindowsCE6
-a----        2013/6/18     11:37           1442 FriendlyARM-电容触摸.ini
-a----       2020/11/11     18:21           1393 FriendlyARM.ini
-a----        2013/7/30     10:00            559 readme.txt
-a----         2015/7/7     11:31         540672 Superboot210.bin

FriendlyARM.ini 是Superboot启动会从中读取的配置文件。包括是Android还是Linux、WinCE

Booting from SD
Bad or missing configure file '/images/FriendlyARM.ini'
Booting from SD

Superboot-210
Ver: 1.27a(20150707a)
// 烧录ing
...

:)

Vexpress-A9 RT-Rthread BSP

========

https://www.rt-thread.org/document/site/application-note/setup/qemu/ubuntu/an0005-qemu-ubuntu/

Ready

git clone https://github.com/RT-Thread/rt-thread.git

sudo apt-get install scons qemu cross_compile

tom@laptop:~$ cd /tmp/
tom@laptop:/tmp$ wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6-2016q4/gcc-arm-none-eabi-6_2-2016q4-20161216-linux.tar.bz2
tom@laptop:/tmp$ tar xf ./gcc-arm-none-eabi-6_2-2016q4-20161216-linux.tar.bz2
tom@laptop:/tmp$ mv gcc-arm-none-eabi-6_2-2016q4/ /opt/
tom@laptop:/tmp$ /opt/gcc-arm-none-eabi-6_2-2016q4/bin/arm-none-eabi-gcc –version

sudo apt-get install libncurses5-dev

vm.min_free_kbytes

内存最安全的阈值

当请求分配内存时,如果有足够的内存,则分配成功。如果没有,则要阻塞,释放内存,再来分配内存。原子请求不能被阻塞,如果分配不到,则失败。内核为了尽量避免原子请求失败,预留了一个页池框,在内存不足时使用。这个页池框的大小就是min_free_kbytes。

echo 500000 > /proc/sys/vm/min_free_bytes

具体含义:保留500M的内存空间,但是由于系统的内存才256MB,导致系统出现kernel panic,系统崩溃了

vm.min_free_kbytes 设置过高,导致 kswapd0 消耗大量 CPU

LINUX tmpfs 空间使用未达到100% , 内存也未占满。 执行任何命令提示 bash: fork: Cannot allocate memory 过几秒时间系统会自动重启。

1.首先判断客户是否内存不足导致,每次执行测试操作后,free 结果显示可用内存是有的

2.当进程Process 比较多,导致无法分配pid,也会提示Cannot allocate memory,执行命令pstree -a | wc -l 统计下进程数,排除进程数过多导致的内存无法分配

内存管理有关的命令

vmstat CPU、内存、IO的使用情况,单位KB

t@m:/sys/bus/usb/devices/1-4# vmstat 2 5
procs ———–memory———- —swap– —–io—- -system– ——cpu—–
r b 交换 空闲 缓冲 缓存 si so bi bo in cs us sy id wa st
0 0 0 9870572 23212 918968 0 0 2 3 16 25 0 0 99 0 0
3 0 0 9870308 23212 919008 0 0 0 0 639 1201 1 1 98 0 0
0 0 0 9870244 23212 919008 0 0 0 0 606 1182 1 1 98 0 0
0 0 0 9870148 23212 919008 0 0 0 0 551 1181 1 1 97 0 0
0 0 0 9870244 23220 919008 0 0 0 8 520 1135 1 1 98 0 0

Supervisor

Supervisor是一个Python编写的进程管理工具,支持Linux/Unix系统(不支持Windows),可以很方便的启动、停止、重启多个进程,可以在程序意外退出后自动重启,记录并输出所有控制台日志,免去了自己编写shell脚本的麻烦

apt install supervisor #安装
systemctl enable supervisor #设置开机自启
supervisord #初始化

添加配置

Supervisor的默认配置目录在/etc/supervisor/conf.d/下

vim /etc/supervisor/conf.d/slimchat.conf #slimchat为自定义名称,下同

[program:slimchat]
command=npm start 启动命令
directory=/home/wwwroot/www.slimchat.ml/SlimChat/ 目录
autostart=true 是否自启
autorestart=true 进程退出后是否自动重启
stderr_logfile=/var/log/slimchat.err.log 错误日志
stdout_logfile=/var/log/slimchat.out.log 输出日志
user=www 用户身份
stopsignal=INT

相关命令

supervisorctl status slimchat #查看进程状态(使用自定义的名称)

supervisorctl stop slimchat #停止

supervisorctl start slimchat #启动

supervisorctl restart slimchat #重启

supervisorctl reload #重启整个服务(注意!此命令会重启所有进程,不推荐)

更新配置后的正确方法:

supervisorctl reread

supervisorctl update

FAQ

Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.

解决

find / -name supervisor.sock
unlink /run/supervisor.sock
supervisord

Timer

内核时间

HZ 是一个和平台相关的全局变量。

https://elixir.bootlin.coam/linux/v4.9.241/source/include/uapi/asm-generic/param.h#L5

#ifndef HZ
#define HZ 100
#endif

https://elixir.bootlin.com/linux/v4.9.241/source/arch/alpha/include/uapi/asm/param.h#L4

#define HZ        1024

一般情况

#define HZ 1000

表示1秒时钟中断产生1000次。

jiffies记录了自系统启动后产生的节拍的总数。jiffies一秒内增加的数量等于HZ

短时间延时用ndekay、udelay、mdelay
长时间延时,用当前jiffies和目标jiffies值比较

unsigned long timeout = jiffies +2 * HZ;
while(time_before(jiffies,timeout));

time_list

struct timer_list {
    /*
     * All fields that change during normal runtime grouped to the same cacheline
     */
    struct list_head entry;
    unsigned long expires;        //超时的Jiffies
    struct tvec_base *base;

    void (*function)(unsigned long); //超时的时候处理的函数
    unsigned long data;

    int slack;

#ifdef CONFIG_TIMER_STATS
    int start_pid;
    void *start_site;
    char start_comm[16];
#endif
#ifdef CONFIG_LOCKDEP
    struct lockdep_map lockdep_map;
#endif
};

操作函数

init_timer
add_timer
mod_timer
del_timer

example

Android X86 Project

六七年前就了解过Phoenix Remix这样的项目, 即给个人PC电脑安装Android系统. 但那时候没有看到能够用户自定义的用户自己编译的Android. 直到在Quectel工作的时候,在用户那里,了解到LineageOS以及Android X86,即可以自己编译的Android系统

https://www.android-x86.org/source.html

准备条件

sudo apt -y install git gcc curl make repo libxml2-utils flex m4
sudo apt -y install openjdk-8-jdk lib32stdc++6 libelf-dev
sudo apt -y install libssl-dev python-enum34 python-mako syslinux-utils
sudo apt-get install openjdk-8-jdk
sudo apt-get install gettext libncurses5

Android 源码

repo init -u http://scm.osdn.net/gitroot/android-x86/manifest -b $branch
repo sync --no-tags --no-clone-bundle

编译

source build/envsetup.sh && lunch android_x86_64-userdebug
m -jX iso_img  2>&1 | tee build.log

编译好的镜像,在虚拟机中烧录测试