Open main menu

DAVE Developer's Wiki β

Changes

Embedded Linux tips and tricks

10,107 bytes added, 09:09, 30 January 2023
no edit summary
__FORCETOC__
 
==Introduction==
This page provides examples and usage notes for common tasks/issues related to typical embedded Linux systems.
==How to write <code>.wic</code> image files to SD cards==
[https://www.yoctoproject.org/ Yocto ] build system can generate [https://www.yoctoproject.org/docs/2.4.2/dev-manual/dev-manual.html#creating-partitioned-images-using-wic <code>.wic</code> image files]. These files are usually written to SD cards to create bootable devices. The simplest way to write such images to SD cards is to use the [https://www.balena.io/etcher/ Balena Etcher] tool, which is available for Linux, macOS, and Windows hosts. Using Etcher is straightforward, nonetheless many tutorials and examples are available on the Internet. Advanced users can also use the well-known [https://en.wikipedia.org/wiki/Dd_(Unix) <code>dd</code>] utility. This tool should be avoided unless the user knows what they are doing. If the target device is not specified properly, <code>dd</code> can wipe out all the data on a host's disk drive! For more details, see for instance [https://opensource.com/article/18/7/how-use-dd-linux this article]. ==Setting up a Yocto prebuilt package repository for <code>apt</code>==Occasionally, it is convenient to set up the target for installing <code>.deb</code> packages retrieved from a Yocto repository. The following example shows how to do that on an [[ORCA_SOM|ORCA SOM]]-based target.The repository used is located at http://yocto.dave.eu/imx-5.4.70-2.3.0/. The prebuilt packages were generated by Yocto Zeus, which was used to create the distro running on the target as well. ===Configuring the network subsystem===First of all, it is necessary to configure the target's network subsystem in order to access the Internet. In this example, a couple of <code>systemd</code> services are used for this purpose, namely <code>systemd-networkd</code> and <code>systemd-resolved</code>. They were configured by following these steps. Disable the Connection Manager (ConnMan) sevice to prevent conflict issues:<pre class="board-terminal">root@orca:~# systemctl disable connman.serviceroot@orca:~# systemctl stop connman.service[ 5809.162942] imx-dwmac 30bf0000.ethernet eth1: Link is Downroot@orca:~# systemctl status connman.service* connman.service - Connection service Loaded: loaded (/lib/systemd/system/connman.service; disabled; vendor preset: enabled) Active: inactive (dead)</pre> Create the configuration file for the network interface of interest (<code>eth1</code> in this case). In the example, the file was <code>/etc/systemd/network/20-eth0.network</code><pre class="board-terminal">[Match]Name=eth1 # Prevent the interface loading if the kernel boots from nfsKernelCommandLine=!nfsroot [Network]Address=192.168.0.163/24Gateway=192.168.0.254DNS=192.168.0.1</pre> Start (or restart) <code>systemd-networkd</code> and <code>systemd-resolved</code>:<pre class="board-terminal">root@orca:~# systemctl restart systemd-networkdroot@orca:~# [ 5867.637252] imx-dwmac 30bf0000.ethernet eth1: PHY [stmmac-1:07] driver [Microchip KSZ9131 Gigabit PHY][ 5867.661532] imx-dwmac 30bf0000.ethernet eth1: No Safety Features support found[ 5867.668779] imx-dwmac 30bf0000.ethernet eth1: IEEE 1588-2008 Advanced Timestamp supported[ 5867.677316] imx-dwmac 30bf0000.ethernet eth1: registered PTP clock[ 5867.683639] imx-dwmac 30bf0000.ethernet eth1: configuring for phy/rgmii-id link mode[ 5867.692915] 8021q: adding VLAN 0 to HW filter on device eth1[ 5867.704764] Micrel KSZ8081 or KSZ8091 30be0000.ethernet-1:03: attached PHY driver [Micrel KSZ8081 or KSZ8091] (mii_bus:phy_addr=30be0000.ethernet-1:03, irq=POLL)[ 5871.775856] imx-dwmac 30bf0000.ethernet eth1: Link is Up - 1Gbps/Full - flow control rx/tx[ 5871.784156] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes readyroot@orca:~# systemctl restart systemd-resolved</pre> Both services should be active:<pre class="board-terminal">root@orca:~# systemctl status systemd-networkd* systemd-networkd.service - Network Service Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-12-15 21:34:32 UTC; 18s ago Docs: man:systemd-networkd.service(8) Main PID: 534 (systemd-network) Status: "Processing requests..." Tasks: 1 Memory: 2.0M CGroup: /system.slice/systemd-networkd.service `-534 /lib/systemd/systemd-networkd Dec 15 21:34:32 orca systemd[1]: Starting Network Service...Dec 15 21:34:32 orca systemd-networkd[534]: Enumeration completedDec 15 21:34:32 orca systemd[1]: Started Network Service.Dec 15 21:34:32 orca systemd-networkd[534]: eth1: IPv6 successfully enabledDec 15 21:34:32 orca systemd-networkd[534]: eth0: IPv6 successfully enabledDec 15 21:34:36 orca systemd-networkd[534]: eth1: Gained carrierDec 15 21:34:38 orca systemd-networkd[534]: eth1: Gained IPv6LLDec 15 21:34:50 orca systemd-networkd[534]: eth1: Configuredroot@orca:~# systemctl status systemd-resolved* systemd-resolved.service - Network Name Resolution Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-12-15 21:34:32 UTC; 6s ago Docs: man:systemd-resolved.service(8) https://www.freedesktop.org/wiki/Software/systemd/resolved https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients Main PID: 542 (systemd-resolve) Status: "Processing requests..." Tasks: 1 Memory: 1.4M CGroup: /system.slice/systemd-resolved.service `-542 /lib/systemd/systemd-resolved Dec 15 21:34:32 orca systemd[1]: Starting Network Name Resolution...Dec 15 21:34:32 orca systemd-resolved[542]: Positive Trust Anchors:Dec 15 21:34:32 orca systemd-resolved[542]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5Dec 15 21:34:32 orca systemd-resolved[542]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8dDec 15 21:34:32 orca systemd-resolved[542]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa>Dec 15 21:34:32 orca systemd-resolved[542]: Using system hostname 'orca'.Dec 15 21:34:32 orca systemd[1]: Started Network Name Resolution.</pre> ===Configuring <code>apt</code>===Edit the file <code>/etc/apt/apt.conf</code> like this:<pre class="board-terminal">APT::Architecture "arm64";APT::Get::AllowUnauthenticated "true";Acquire::Languages "none";</pre>  Edit the file <code>/etc/apt/sources.list.d/debian-10.list</code> like this:<pre class="board-terminal">root@desk-mx8mp:~# cat /etc/apt/sources.list.d/debian-10.listdeb [trusted=yes] http://yocto.dave.eu/imx-5.4.70-2.3.0/ all/deb [trusted=yes] http://yocto.dave.eu/imx-5.4.70-2.3.0/ aarch64/deb [trusted=yes] http://yocto.dave.eu/imx-5.4.70-2.3.0/ aarch64-mx8mp/</pre>  Execute the following commands:<pre class="board-terminal">root@desk-mx8mp:~# rm -rf /var/lib/apt/lists/*root@desk-mx8mp:~# apt-get cleanroot@orca:~# apt-get update0% [Working]Ign:1 http://yocto.dave.eu/imx-5.4.70-2.3.0 all/ InReleaseIgn:2 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ InReleaseIgn:3 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64-mx8mp/ InReleaseGet:4 http://yocto.dave.eu/imx-5.4.70-2.3.0 all/ Release [1213 B]Get:5 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ Release [1217 B]Get:6 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64-mx8mp/ Release [1223 B]Ign:7 http://yocto.dave.eu/imx-5.4.70-2.3.0 all/ Release.gpgIgn:8 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ Release.gpgIgn:9 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64-mx8mp/ Release.gpgGet:10 http://yocto.dave.eu/imx-5.4.70-2.3.0 all/ Packages [146 kB]Get:11 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ Packages [2848 kB]Get:12 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64-mx8mp/ Packages [283 kB]Fetched 3280 kB in 6s (545 kB/s)Reading package lists... Doneroot@orca:~# sed -i 's/\.\//aarch64\//g' /var/lib/apt/lists/yocto.dave.eu_imx-5.4.70-2.3.0_aarch64_Packagesroot@orca:~# sed -i 's/\.\//all\//g' /var/lib/apt/lists/yocto.dave.eu_imx-5.4.70-2.3.0_all_Packagesroot@orca:~# sed -i 's/\.\//aarch64-mx8mp\//g' /var/lib/apt/lists/yocto.dave.eu_imx-5.4.70-2.3.0_aarch64-mx8mp_Packages</pre>  The target is finally ready to install new packages. The following example shows for instance the installation of <code>vim</code>:<pre class="board-terminal">root@orca:~# sudo apt-get install vimReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: vim-common vim-help vim-syntax vim-tutor vim-vimrcThe following NEW packages will be installed: vim vim-common vim-help vim-syntax vim-tutor vim-vimrc0 upgraded, 6 newly installed, 0 to remove and 20 not upgraded.Need to get 6584 kB of archives.After this operation, 0 B of additional disk space will be used.Do you want to continue? [Y/n] YGet:1 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim 8.1.1518-r0 [1051 kB]Get:2 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim-common 8.1.1518-r0 [2314 kB]Get:3 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim-help 8.1.1518-r0 [1757 kB]Get:4 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim-syntax 8.1.1518-r0 [1049 kB]Get:5 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim-tutor 8.1.1518-r0 [411 kB]Get:6 http://yocto.dave.eu/imx-5.4.70-2.3.0 aarch64/ vim-vimrc 8.1.1518-r0 [1596 B]Fetched 6584 kB in 9s (660 kB/s)Selecting previously unselected package vim.(Reading database ... 71726 files and directories currently installed.)Preparing to unpack .../vim_8.1.1518-r0_arm64.deb ...Unpacking vim (8.1.1518-r0) ...Selecting previously unselected package vim-common.Preparing to unpack .../vim-common_8.1.1518-r0_arm64.deb ...Unpacking vim-common (8.1.1518-r0) ...Selecting previously unselected package vim-help.Preparing to unpack .../vim-help_8.1.1518-r0_arm64.deb ...Unpacking vim-help (8.1.1518-r0) ...Selecting previously unselected package vim-syntax.Preparing to unpack .../vim-syntax_8.1.1518-r0_arm64.deb ...Unpacking vim-syntax (8.1.1518-r0) ...Selecting previously unselected package vim-tutor.Preparing to unpack .../vim-tutor_8.1.1518-r0_arm64.deb ...Unpacking vim-tutor (8.1.1518-r0) ...Selecting previously unselected package vim-vimrc.Preparing to unpack .../vim-vimrc_8.1.1518-r0_arm64.deb ...Unpacking vim-vimrc (8.1.1518-r0) ...Setting up vim (8.1.1518-r0) ...update-alternatives: Linking /bin/vi to /usr/bin/vim.vimupdate-alternatives: Linking /usr/bin/vim to /usr/bin/vim.vimupdate-alternatives: Linking /usr/bin/xxd to /usr/bin/xxd.vimSetting up vim-common (8.1.1518-r0) ...Setting up vim-help (8.1.1518-r0) ...Setting up vim-syntax (8.1.1518-r0) ...Setting up vim-tutor (8.1.1518-r0) ...Setting up vim-vimrc (8.1.1518-r0) ...</pre> == Setting-up an Ethernet point-to-point link between the host and the target ==TBD
The simplest way to write such images is to use [httpsCaso 1://www.balena.io/etcher/ Balena Etcher] tool, which is available for Linux, macOS, and Windows hosts. Using Etcher is straightforward, nonetheless many tutorials and examples are available on the Internet.host
Advanced users can also use the well-known [httpsCaso 2://en.wikipedia.org/wiki/Dd_(Unix) <code>dd</code>] utility. This tool should be avoided unless the user knows what they are doing. If the target device is not specified properly, <code>dd</code> can wipe out all the data on Linux host's disk drive! For more details, see for instance [https://opensource.com/article/18/7/how-use-dd-linux this article].
4,650
edits