2020年3月16日 星期一

在ARMV8開發板透過DTS 預留memory, 避開資源衝突!


/usr/local/Cavium_Networks/OCTEONTX-SDK/dts/ 找到相對應的  xxxxxx-linux.dts
xxxxboard name
然後加入 /memreserve/ 0x0000000010000000 0x0000000010000000;
                                                       Start address                               size
(device tree spec寫說要64 bits格式,所以我没省略前面的0,不知道可不可以省略。)


加在開頭的地方,如下圖:


然後make uboot-build PLAT=t83,得到imageupdate









另外可以修正PEM 避開pci resource 與 主版 memory resource 衝突的方式
目前已經找到workaround的方式,方法為修改device treePEMrangesranges會決定PEM mapping給底下device BAR的起始位置,如下圖標示起來的地方

原本為 0x00 0x10000000 0x8810 0x10000000
修改成0x00 0x00000000 0x8810 0x00000000

修改後,PEM在設定BAR時,會從0x0000 0000開始,
由於CN83XXSystem RAM是由0x0280 0000開始(前面保留給其它device)
這樣子的設定就避開了System RAM的區段,如下圖









2020年3月15日 星期日

** Ubuntu系統 用 make-kpkg 核心編譯


**  Ubuntu系統 用 make-kpkg 核心編譯

    編譯Linux核心安裝所需的套件
    $ sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils kernel-package libssl-dev
 
    下載Linux核心原始碼
    $ wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.5.tar.xz
    $ tar xvf linux-4.5.tar.xz
 
    設定Linux核心
    $ cd linux-4.5
 
    清除先前編譯的暫存檔案
    $ sudo make mrproper
 
    載入系統核心設定
    $ cp /boot/config-$(uname -r) .config
 
    修改核心功能與驅動程式設定項目
    $ make menuconfig
 
    編譯Linux核心並建立DEB套件包
    $ sudo make-kpkg --initrd kernel_image kernel_headers
    或
    $ sudo make-kpkg --initrd --revision=1.0 --append-to-version -20200313 kernel_image kernel_headers
 
    安裝核心, 在上層目錄裡生成deb安裝包,使用dpkg -i 安裝,安裝完成後重開即可。
    $ sudo dpkg -i linux-image-*.deb
    $ sudo dpkg -i linux-headers-*.deb
     
    1、--initrd選項會讓make-kpkg自動幫我們生成initramfs;
    2、--revision會給生成的deb檔案加上一個版本資訊。這個引數只是影響到檔名,如果不指定,預設會是“10.00.Custom”;
    3、--append-to-version也是一種版本資訊,它不僅出現在deb安裝包的檔名裡,也會影響到kernel的名稱。
    核心更新完成之後,用“uname -r”察看會得到“4.5-20200313”;

2020年3月13日 星期五

** Ubuntu 移除不用的kernel

**  Ubuntu 移除不用的kernel

1.  檢查目前正在用哪個kernel
    # uname -a

2.  或者列出目前系統中已安裝哪些kernel
    # dpkg --get-selections | grep linux-image

3.  移除不要的Kernel,會自動將相關版本的 linux-image-extra-* 也一併移除
    # sudo apt-get purge linux-image-X.X.XX-XX-generic

Ubuntu OS 透過 apt-get install 直接update kernel

** 使用ubuntu OS支援不用compiler直接update kernel

1.  搜尋支援的kernel
    # sudo apt-cache search linux-image-*
 
    linux-image-4.8.0-56-generic - Linux kernel image for version 4.8.0 on 64 bit x86 SMP
    linux-image-4.8.0-58-generic - Linux kernel image for version 4.8.0 on 64 bit x86 SMP
    ...
 
2.  開始安裝kernel
    # sudo apt-get install linux-image-4.8.0-56-generic
 
    如果有其他需求,像是編譯模組,可以連headers都裝上
    # sudo apt-get install linux-headers-4.8.0-56-generic
 
3.  安裝後,更新initramfs image,詳細 man update-initramfs
    Update the initramfs of the newest kernel:
    # update-initramfs -u
            or
    Create the initramfs for a specific kernel:
    # update-initramfs -c -k 4.8.0-58-generic
 
4.  接著更新grub清單,完成!
    # sudo update-grub

2020年3月12日 星期四

自己創建 ubuntu rootfs 18.04 遇到 sudo su error

sudo su error


如果執行sudo命令的用戶沒有執行sudo的權限,執行sudo命令時會報下面的錯
*** error: sudo: unable to resolve host localhost.localdomain
    修正 /etc/hosts
    增加 127.0.0.1       localhost.localdomain
    重啟服務 Ubuntu: $sudo/etc/init.d/networking restart

*** error: accusys is not in the sudoers file. This incident will be reported.
    #su root
    #chmod u+w /etc/sudoers
    #vi /etc/sudoers
 
        #
        # This file MUST be edited with the 'visudo' command as root.
        #
        # Please consider adding local content in /etc/sudoers.d/ instead of
        # directly modifying this file.
        #
        # See the man page for details on how to write a sudoers file.
        #
        Defaults        env_reset
        Defaults        mail_badpass
        Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
     
        # Host alias specification
     
        # User alias specification
     
        # Cmnd alias specification
     
        # User privilege specification
        root    ALL=(ALL:ALL) ALL
        accusys ALL=(ALL:ALL) ALL //加入名單
     
        # Members of the admin group may gain root privileges
        %admin ALL=(ALL) ALL
     
        # Allow members of group sudo to execute any command
        %sudo   ALL=(ALL:ALL) ALL
     
        # See sudoers(5) for more information on "#include" directives:
     
        #includedir /etc/sudoers.d
 
    #chmod u-w /etc/sudoers

2020年3月11日 星期三

Win10滑鼠右鍵選單傳送到新增子選單選項的方法

copy form: https://www.itread01.com/p/912291.html

開啟Win10檔案資源管理器視窗(開啟“這臺電腦”或任一資料夾即可),然後在資源管理器視窗的位址列中輸入 shell:sendto ,
Enter或點選位址列右側的“轉到”箭頭即可開啟“SendTo(傳送到)”目錄。

你可以在“SendTo”資料夾中新建一個資料夾,或者為常用資料夾建立一個快捷方式,然後把常用資料夾的快捷方式放置到這裡。然後你再在某個檔案或資料夾上點選右鍵,在右鍵選單的“傳送到”子選單中就會看到新新增的檔案夾了。

Win10滑鼠右鍵選單傳送到新增子選單選項的方法_Windows

2020年2月27日 星期四

** 如何製作ubuntu arm64的rootfs檔案 **


------------------------------------------------------------
** 如何製作ubuntu arm64的rootfs檔案 **
source form: https://www.itread01.com/content/1545126143.html
------------------------------------------------------------

  **建立 ubuntu-rootfs
    $ mkdir ~/ubuntu-rootfs && cd ubuntu-rootfs

  **下載最新的arm64 ubuntu release image
    $ wget http://cdimage.ubuntu.com/ubuntu-base/releases/18.04/release/ubuntu-base-18.04-base-arm64.tar.gz
    $ tar -xpf ubuntu-base-18.04-base-arm64.tar.gz

    我們解壓縮後,就可以直接刪除這個下載的ubuntu-base-16.04.2-base-arm64.tar.gz檔案了。ls 命令之後的樣子是這樣的:
    [email protected]:~/ubuntu-rootfs$ ls
    bin   dev  home  media  opt   root  sbin  sys  usr
    boot  etc  lib   mnt    proc  run   srv   tmp  var
   
    或是抓取 ubuntu-18.04.4-server-arm64.iso
    mount ubuntu-18.04.4-server-arm64.iso rootfs_18.04
    在 install 目錄下 filesystem.squashfs,這就是根文件系統
    安裝解壓縮工具: apt-get install squashfs-tools
    解壓縮 unsquashfs filesystem.squashfs 會得到 squashfs-root
    內容會得到 filesystem
    bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
 
  **安裝 qemu-user-static
    我們可以使用如下的指令來完成對qemu-user-static的安裝
    $ pwd
    /home/user/ubuntu-rootfs
    $ apt-get install qemu-user-static
    $ cp /usr/bin/qemu-aarch64-static  usr/bin
    $ cp -b /etc/resolv.conf etc/
    在這裡我們要注意的是我們針對arm64的qemu-user-static安裝的檔案是qemu-aarch64-static。
   
  **mount proc, sys, dev, dev/pts到新的檔案系統
    https://raw.githubusercontent.com/psachin/bash_scripts/master/ch-mount.sh
    利用一個簡單的ch-mount.sh指令碼來完成這個動作。它可以幫我們mount及unmount。我們把下載好的指令碼置於ubuntu-rootfs目錄的上一級目錄,並做如下的處理:

    [email protected]:~$ chmod a+x ch-mount.sh
    [email protected]:~$ sudo bash ch-mount.sh -m ubuntu-rootfs/
    [sudo] user 的密碼:
    MOUNTING
    [email protected]:/#
    這樣我們就進入到chroot的環境中了。
   
  **更新系統並安裝所需要的包
    運用如下的命令來更新系統,並安裝所需要的包。依賴網路環境,安裝的時間可能會有差異。
    [email protected]:/# apt-get update
    [email protected]:/# apt-get install -y language-pack-en-base sudo ssh net-tools ethtool wireless-tools
                         lxde xfce4-power-manager xinit xorg network-manager iputils-ping rsyslog lightdm-gtk-greeter
                         alsa-utils gnome-mplayer lightdm bash-completion lxtask htop python-gobject-2 python-gtk2 synaptic
 
    修正版: 只安裝基本需求
    apt-get install -y language-pack-en-base sudo ssh net-tools ethtool wireless-tools network-manager ifupdown iputils-ping rsyslog htop vim
   
    sudo apt-get update
    安裝make rool: sudo apt-get install  gcc automake autoconf libtool make
    安裝vim 編輯器:apt-get install vim
    安裝固件(顯卡固件包含在裡面,必須安裝):apt-get install linux-firmware(如果已拷貝,則不必安裝)
    安裝libncurses5-dev,內核配置make menuconfig 時依賴的庫:apt-get install libncurses5-dev
    安裝內核編譯所需工具:apt-get install bc
    安裝u-boot-tools,編譯uImage 用:apt-get install u-boot-tools
    安裝gcc g++: apt-get install gcc g++
    安裝gfortran: apt-get install gfortran
    安裝ssh: apt-get install ssh
    安裝ifupdown,自動開啟網卡: apt-get install ifupdown
    安裝網絡工具nettools: apt-get install net-tools
    如果需要安裝圖形界面:
    apt-get install xinit gdm3 ubuntu-desktop
    安裝完後重啟系統,這時可以進入圖形界面了。有時可能會遇到鼠標和鍵槃無法使用情況,在內核選項中將
    INPUT_EVDEV 選上即可。
    這時候會提醒語言包的錯誤:
    修改/etc/default/locale 文件,添加以下內容
    LANG="en_US.UTF-8"
    LANGUAGE="en_US:en"
    LC_ALL="en_US.UTF-8"
    執行命令locale-gen en_US.UTF-8 即可。
    這時sudo su 還無法切換到root 用戶,在root 登陸下修改:
    chown root:root /usr/bin/sudo
    chmod 4755 /usr/bin/sudo
    這時在普通用戶下sudo su 就可以臨時切換到root 了。
    如果出現root ssh 無法登陸現象,在/etc/ssh/sshd_config 文件中修改PermitRootLogin yes
    重啟ssh 服務,再次登陸就可以了。
 
  **make modules_install INSTALL_MOD_PATH=/home/sam/rootfs/rootfs_18.04
   
  **設置root密碼
    passwd root
 
  **創建用戶
    adduser accusys
   
  **設置主機名稱和本機IP
    echo "i.MX6" > /etc/hostname
    echo "127.0.0.1 localhost" >> /etc/hosts
    echo "127.0.1.1 i.MX6" >> /etc/hosts
   
  **配置串口和網絡dhcp
    首先配置串口,這裏踩了幾次坑,下載到板子上以後發現串口無法輸出到超級終端,找了很多方案,終於試出來了,需要做一個鏈接才行。
    ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service
    由於我用的是i.mx6ul的平臺,需要添加一個名?getty@ttymxc0.service的鏈接,連接到getty@.service服務。i.mx的平臺是ttymxc0,其他平臺的名字就不清楚了。如果確定不了名字,一個比較笨的方法就是先把製作好的根文件系統下載到開發板上,超級終端上查看打印出來的log,會在 waiting for device dev-ttymxc0.device 時出現 [Time out] ,Dependency failed for Serial Getty on ttymxc0. 由此就可以知道了。
   
   
  **配置DHCP,也可以等下載到開發板之後在配置,但?動時會很慢。
    echo auto eth0 > /etc/network/interfaces.d/eth0
    echo iface eth0 inet dhcp >> /etc/network/interfaces.d/eth0
    /etc/init.d/networking restart

  **系統基礎改造
    # useradd -s '/bin/bash' -m -G adm,sudo yourusername
    # echo "Set password for yourusername:"
    # passwd yourusername
    # echo "Set password for root:"
    # passwd root
   
  **設定主機名
    # echo 'ubuntu.yourusername' > /etc/hostname
   
  **設定自動更新DNS
    # apt-get install resolvconf
    # dpkg-reconfigure resolvconf
   
  **新增主機入口到/etc/hosts:
    127.0.0.1    localhost
    127.0.1.1    yourhostname
   
  **設定timezone
    # apt-get install tzdata
    # dpkg-reconfigure tzdata
   
  **在lib目錄下建立目錄並拷入我們自己硬體相關的模組檔案
    我們可以從我們的host中拷入我們想要的arm64的模組到系統中,比如:
    # cp -r /opt/out/modules/3.4.5 ~/ubuntu-rootfs/lib/modules
    在這裡,我們把我們想要定製的包拷入到lib之下的modules中。
   
  **選項:啟動serial console登入
    我們可以建立/etc/init/ttyS0.conf檔案,並寫入如下的內容:
   
    start on stopped rc or RUNLEVEL=[12345]
    stop on runlevel [!12345]
    respawn
    exec /sbin/getty -L 115200 ttyS0 vt102
   
    在host中可以同如下的命令來登入:
    $ sudo start ttyS0
    等我們完成上面的工作後,我們就可以開始製作我們的rootfs檔案了。在上面我們已經把我們所需要的檔案拷入到相應的檔案目錄之中了。
   
  **退出並製作可燒錄的韌體
    [email protected]:/# exit         
    exit
    [email protected]:~$ pwd
    /home/user
    [email protected]:~$ ./ch-mount.sh -u ubuntu-rootfs
   
  **使用dd指令製作空的韌體容器
    $ dd if=/dev/zero of=ubuntu-rootfs.img bs=1M count=2048
    $ sudo  mkfs.ext4  ubuntu-rootfs.img
   
  **將arm64檔案系統內容製作到ubuntu-rootfs.img
    $ mkdir  ubuntu-mount
    $ sudo mount ubuntu-rootfs.img ubuntu-mount/
    $ sudo cp -rfp ubuntu-rootfs/*  ubuntu-mount/
    $ sudo umount ubuntu-mount/
    $ e2fsck -p -f ubuntu-rootfs.img
    $ resize2fs -M ubuntu-rootfs.img
    這樣最終,我們生成了我們所需要的ubuntu-rootfs.img檔案:
   
    [email protected]:~$ ls ubuntu-rootfs.img -hal
    -rw-rw-r-- 1 user user 2.0G 10月 31 16:23 ubuntu-rootfs.img
    [email protected]:~$ file ubuntu-rootfs.img
    ubuntu-rootfs.img: Linux rev 1.0 ext4 filesystem data, UUID=9ed3cd8b-e81a-4ec9-a8e0-bd185f223936 (needs journal recovery) (extents) (large files) (huge files)
   
  **參考文章:
    https://gnu-linux.org/building-ubuntu-rootfs-for-arm.html
    https://olimex.wordpress.com/2014/07/21/how-to-create-bare-minimum-debian-wheezy-rootfs-from-scratch/
   
ch-mount.sh ---------------------------------------->
#!/bin/bash
#

function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc ${2}proc
    sudo mount -t sysfs /sys ${2}sys
    sudo mount -o bind /dev ${2}dev
    sudo mount -o bind /dev/pts ${2}dev/pts
    sudo chroot ${2}
}

function umnt() {
    echo "UNMOUNTING"
    sudo umount ${2}proc
    sudo umount ${2}sys
    sudo umount ${2}dev/pts
    sudo umount ${2}dev

}

if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
else
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}
fi
ch-mount.sh <----------------------------------------