[轉] Yocto嵌入式開發框架編譯環境構建

前置條件

linux系統,redhat(centos)。可以用伺服器,或者虛擬機系統

以下步驟,啥也別問,跟著搞就是了

基礎lib庫

yum install sqlite-devel
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

yum install -y diffstat

yum install -y patch makeinfo bzip2 chrpath file

yum install -y texinfo

yum install gcc-c++

yum install perl*

yum install -y perl-Thread-Queue

重頭戲來了

安裝python3(注意不是python2)

tar xf Python-3.6.0.tgz

./configure –prefix=/usr/local/python3/

然後就是make && make install

配置環境變量

vim /etc/profile.d/python3.sh

export PATH=$PATH:/usr/local/python3/bin/

source ~/.bash_profile

pip3 install [pkg_name]

安裝perl

wget http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz

tar -zxvf perl-5.16.1.tar.gz

./Configure -des -Dprefix = / usr / local / perl

然後就是make && make install

安裝bitbake

git://git.openembedded.org/bitbake將bin加入$ PATH

bitbake -h預期成功啟動

最後

enjoy your bitbake~~


Reference: https://www.jianshu.com/p/9186b3203fd3

[C/C++] Register值修改

直接看範例:

Example 1:
*((volatile unsigned char *) 0x1e) = 0x16;
這句等義於:
volatile unsigned char *ptr = 0x1e;
*ptr = 0x16;

Example 2:
char reg8 = *((volatile unsigned char *) 0x1e);
reg8 = reg8 | (1<<7);
*((volatile unsigned char *) 0x1e) = reg8;
等義於:
unsigned char reg8 = *((volatile unsigned char *) 0x1e);
reg8 = reg8 | (1<<7);
volatile unsigned char *ptr = 0x1e;
*ptr = reg8;

參考文章: https://blog.csdn.net/wear_/article/details/52129421

HAL層設計的10個技巧

1.明確的硬體核心功能
2.避免設計一個全家餐HAL(實務:function最多只能傳入1個參數)
4.使用Doxygen來撰寫HAL
5.多找一雙眼來設計
6.別害怕重構
7.保持在30,000英呎的視野
8.使用一致性的命名規則
9.包含一個可傳遞參數的初始化function
10.提供測試套件(for不同硬體)

原文出處: https://www.edn.com/electronics-blogs/embedded-basics/4439613/10-Tips-for-designing-a-HAL

參考: Android HAL層架構

BMC用NFS debug的方法

前置作業:
1. Build好的uImage放tftp
2. Build/output/ImageTree目錄放NFS export path備用
3. 登入BMC console測試是否可mount NFS: mount -t nfs -o rw,nolock {src_nfs_path} {dest_path}

NFS開機模式步驟:
1. 重啟BMC,當BMC出現Hit any key to stop autoboot:時按任意鍵,進入u-boot畫面

2. 設定環境變數: (在本機的u-boot)

3.1 備份原本環境變數
print #複製下來另存新檔

3.2 設定環境變數
setenv ipaddr {ipaddr} #給u-boot一個隨意靜態IP
setenv serverip {serverip} #設定tftp server IP
setenv bootcmd 'tftp 82000000 uImage; bootm 82000000' #設定從tftp的uImage開機
(原本是bootcmd=bootfmh #從本機load進memory的uImage開機,復原時只要改回這個即可)
setenv bootargs 'root=/dev/nfs rw nfsroot={nfs_ip}:{nfs_export_path} ip=dhcp console=ttyS4,38400' #設定BMC檔案系統root從NFS mount起來,並給予BMC dhcp IP
(如要指定static ip, ip={bmcip}:{serverip}:{gatewayip}:{netmask}::{bmcnicname}:off)
(如果mount nfs出現錯誤,首先要在bootargs放上nfsrootdebug參數找出真正的原因,若是沒加nolock的問題,將nfsroot=最後加上nolock即可,i.e.nfsroot={nfs_ip}:{nfs_export_path},nolock)
saveenv #存檔寫回本機的uImage

tftp 82000000 uImage #測試tftp的uImage能不能load進memory
bootm 82000000 #從0x82000000記憶體開機

3.3 執行重開機
run bootcmd
登入BMC後查看/proc/cmdline,是否載入kernal是我們bootcmd寫的NFS參數

U-boot指令:
http://flykof.pixnet.net/blog/post/22975136-u-boot%E6%8C%87%E4%BB%A4

BMC default IP: 192.168.0.120
Baud rate: 38400 / 115200

TFTP installation:
https://yulun.me/2016/setup-tftp-server-on-ubuntu/

arp_cache設定

arp_cache: neighbor table overflow!

#sysctl -w net.ipv4.neigh.default.gc_thresh3=8192
#sysctl -w net.ipv4.neigh.default.gc_thresh2=8192
#sysctl -w net.ipv4.neigh.default.gc_thresh1=4096

https://www.serveradminblog.com/2011/02/neighbour-table-overflow-sysctl-conf-tunning/

怎麼增大Linux系統的open file(s)上限

 

#查看或設置open file限制

ulimit -n

 

@soft limit,軟限制,用戶可以上調軟限製到硬限制

ulimit -Sn

@hard limit,硬限制,非root用戶不能修改

ulimit -Hn

如果沒有指明,則同時修改軟限制和硬限制。

 

#臨時修改和永久修改

臨時修改只對當前會話有效,登出和重啟後都恢復系統設置。

@臨時修改

使用ulimit命令,以修改open file(s)為例。

ulimit -n 1024000

查看修改結果

ulimit -n

1024000

@臨時修改某個PID

prlimit -n4096 -p pid_of_process 

@永久修改

在/etc/security/limits.conf

或者在/etc/security/limits.d/目錄下添加一個文件。

具體格式參考/etc/security/limits.conf

 

#open file(s)上限

open file(s)kernel級別有2個配置,分別是:

fs.nr_open,進程級別

fs.file-MAX,系統級別

fs.nr_open默認設置的上限是1048576,所以用戶的open file(s)不可能超過這個上限。

@sysctl命令修改上限(臨時)

#sysctl -w fs.nr_open = 10000000

#ulimit -n 10000000

#ulimit -n

10000000

@修改上限(永久)

到/etc/sysctl.conf中

例如:

#echo“fs.nr_open = 10000000”>> /etc/sysctl.conf

#echo“fs.file-max = 11000000”>> /etc/sysctl.conf

注意:fs.nr_open總是應該小於等於fs.file-max。

 

#查看當前打開的文件數:

#sysctl fs.file-nr

fs.file-nr = 1760 0 11000000

 

參考:

http://www.chengweiyang.cn/2015/11/14/how-to-enlarge-linux-open-files-upper-cell/

Understanding Metaclass

http://blog.jobbole.com/21351/

http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python

Understanding Systemd Units, Unit Files and Directives

https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

Git GC and reflog expire

git reflog expire –expire=now –all # Expire reflog immediately
git gc –prune=now # Remove dangling loose objects
git repack -ad # Remove dangling objects from packfiles (optional)
git fsck –unreachable # Check loose objects connectivity and validity

http://stevelorek.com/how-to-shrink-a-git-repository.html

https://gitbook.tw/chapters/faq/remove-files-from-git.html

https://stackoverflow.com/questions/5277467/how-can-i-clean-my-git-folder-cleaned-up-my-project-directory-but-git-is-sti

https://ithelp.ithome.com.tw/articles/10138150

Python magic methods & mixin

Magic methods: http://pycoders-weekly-chinese.readthedocs.io/en/latest/issue6/a-guide-to-pythons-magic-methods.html

Mixin: https://news.ycombinator.com/item?id=7994505