how to config u-boot for imx6? - embedded-linux

When I am trying to make u-boot for apalis-aimx6-quad board, and below list is shows the details of my configuration:
CROSS_COMPILER = aarch64-unknown-linux-gnu
1.1 it already exported to path
1.2 menuconfig of the cross compiler remains as before.
Host Linux version = 5.4.0-109-generic #123~18.04.1-Ubuntu
version of the cross compiler : crosstool-ng-1.25-rc2
according to the mentioned software and hardware properties, I faced with the following error when i try to make the boot-loader for my board using u-boot:
cc1: error: bad value (‘generic-armv7-a’) for ‘-mtune=’ switch
cc1: note: valid arguments to ‘-mtune=’ switch are: nocona core2 nehalem corei7
westmere sandybridge corei7-avx ivybridge core-avx-i haswell core-avx2 broadwell
skylake skylake-avx512 bonnell atom silvermont slm knl intel x86-64 eden-x2
nano nano-1000 nano-2000 nano-3000 nano-x2 eden-x4 nano-x4 k8 k8-sse3 opteron
opteron-sse3 athlon64 athlon64-sse3 athlon-fx amdfam10 barcelona bdver1 bdver2 bdver3
bdver4 znver1 btver1 btver2 generic
scripts/Makefile.build:147: recipe for target 'lib/asm-offsets.s' failed
make[1]: *** [lib/asm-offsets.s] Error 1
Makefile:1965: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
what can be the error solution?
and the Second question is:
in the ./ct-ng list-samples what type of samples are suitable for my board?
CPU-NAME = NXP® i.MX 6Quad
CPU-TYPE : 4x Arm Cortex™-A9
CPU-CLOCK : 800MHz
FLOATING-POINT-UNIT : VFPv3

You are using the wrong compiler, i.e. the gcc from your Linux PC, this is why the error message is suggesting to use values such as corei7 for the -mtune option.
This being said, because your apalis-aimx6-quad SoC is a Cortex-A9,its architecture is Armv7-a and you therefore cannot use a compiler targeting the Armv8-a architecture, such as the aarch64-unknown-linux-gnu-gcc you are using. You should rather use, say, arm-unknown-linux-gnu-gcc or arm-none-eabi-gcc.I would strongly suggest to use an official Arm toolchain, such as this one (available here), for building u-boot, and to avoid using the latest 11.2 version: I have been unable to build u-boot when using it because of an internal compiler error.
You should use CROSS_COMPILE=, and not CROSS_COMPILER= in your build command,and this is the reason why you were using your system gcc instead of aarch64-unknown-linux-gnu-gcc for building u-boot.
Bottom line, your build command should be something like:
CROSS_COMPILE=arm-none-eabi- make mrproper apalis_imx6_defconfig all
After completion of the build command, you should see the u-boot artefacts:
ll u-boot*
-rwxrwxr-x 1 user user 4988448 May 13 07:56 u-boot*
-rw-rw-r-- 1 user user 569504 May 13 07:56 u-boot-dtb.bin
-rw-rw-r-- 1 user user 569568 May 13 07:56 u-boot-dtb.img
-rwxrwxr-x 1 user user 512920 May 13 07:56 u-boot-nodtb.bin*
-rw-rw-r-- 1 user user 639200 May 13 07:56 u-boot-with-spl.imx
-rw-rw-r-- 1 user user 569504 May 13 07:56 u-boot.bin
-rw-rw-r-- 1 user user 18081 May 13 07:55 u-boot.cfg
-rw-rw-r-- 1 user user 10858 May 13 07:55 u-boot.cfg.configs
-rw-rw-r-- 1 user user 56584 May 13 07:56 u-boot.dtb
-rw-rw-r-- 1 user user 569568 May 13 07:56 u-boot.img
-rw-rw-r-- 1 user user 1719 May 13 07:56 u-boot.lds
-rw-rw-r-- 1 user user 1100407 May 13 07:56 u-boot.map
-rwxrwxr-x 1 user user 1538914 May 13 07:56 u-boot.srec*
-rw-rw-r-- 1 user user 195657 May 13 07:56 u-boot.sym

I also do the same thing for RPI 4 which the following command lines do:
wget https://dev.iopsys.eu/fork/uboot.git
tar -xf u-boot.tar.gz
ls ./configs
ls ./configs|grep rpi
make rpi_4_defconfig
export PATH=/home/<your user name>/x-tools/aarch64-rpi4-linux-gnu/bin/:$PATH
type aarch an hit tab if system recognize the compiler continue else
go back and export the compiler path.
export CROSS_COMPILE=aarch64-rpi4-linux-gnu-
make menuconfig
make
------------------------------------------------------------------------
cd ..
mkdir sdcard
sudo cp ../u-boot/u-boot.bin .
wget
------------------------------------------------------------------------
PREPARE MEMORY FOR BOOT
connect your memory to pc.
lsblk --> to know what is the name of the memory (assume it is sdb)
sudo umount /dev/sdb1
sudo cfdisk /dev/sdb --> erase older partitions and clear on 100M partition
-- note : type of the partition have to be fat32
once the partition is created.
sudo mkfs.vfat /dev/sdb1
sudo mount /dev/sdb1 /mnt
wget https://github.com/raspberrypi/firmware/raw/master/boot/start4.elf
wget https://github.com/raspberrypi/firmware/raw/master/boot/bcm2711-rpi-4-b.dtb
gedit config.txt
--#######################
IN THE CONFIG
enable_uart=1
kernel=u-boot.bin
arm_64bit=1
--#######################
cat config.txt
sudo cp * /mnt
sudo umount /mnt
unconnect the memory and connect it to the target machine.

Related

How to insert the configuration.nix file inside my dot files?

I am creating my dot files following this tutorial. It successfully works for emacs.d.
Since I am using NixOS, I tried doing exactly the same steps with symlink creation for the configuration.nix file. Thus, I did:
1 - On terminal:
[pedro#system:/etc/nixos]$ sudo mv /etc/nixos/configuration.nix ~/.dotfiles/
2 - Then:
[pedro#system:/etc/nixos]$ ln -sf ~/.dotfiles/configuration.nix configuration.nix~
3 - It seems to work fine, as I do:
[pedro#system:/etc/nixos]$ ls -la
total 12
drwxr-xr-x 2 root root 4096 Dec 1 21:41 .
drwxr-xr-x 32 root root 4096 Dec 1 22:00 ..
lrwxrwxrwx 1 root root 39 Dec 1 21:41 configuration.nix~ -> /home/pedro/.dotfiles/configuration.nix
-rw-r--r-- 1 root root 842 Nov 12 17:40 hardware-configuration.nix
After doing some editions and saving the changes, I can't do nixos-rebuild switch, though. It throws an error:
[pedro#system:/etc/nixos]$ sudo nixos-rebuild switch
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)
building Nix...
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)
building the system configuration...
warning: Nix search path entry '/etc/nixos/configuration.nix' does not exist, ignoring
error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/default.nix:1:60
(use '--show-trace' to show detailed location information)
The ~ after configuration.nix~ might be the problem here. How can I fix this?
Thanks!
Your Step 2 seems to have cause the issue here: The symlink should be called configuration.nix not configuration.nix~ as you have noticed.
You could fix this by running mv configuration.nix~ configuration.nix in the /etc/nixos folder which would rename configuration.nix~ to the correct configuration.nix.

Buildroot - building ISO image

Firs, please excuse me - those are my first steps in building OS and using Buildroot.
I've managed to create my first custom os (nothing special, just a first test with patched 4.6.3 kernel with grsec).
I have this files in /output/images dir:
$ ls -lh
total 304M
-rw-r--r-- 1 fugitive fugitive 512 Apr 13 01:01 boot.img
-rw-r--r-- 1 fugitive fugitive 4.1M Apr 13 00:57 bzImage
-rw-r--r-- 1 fugitive fugitive 79M Apr 13 01:01 disk.img
-rw-r--r-- 1 fugitive fugitive 137K Apr 13 00:57 grub-eltorito.img
-rw-r--r-- 1 fugitive fugitive 137K Apr 13 00:57 grub.img
-rw-r--r-- 1 fugitive fugitive 69M Apr 13 01:01 rootfs.cpio
-rw-r--r-- 1 fugitive fugitive 79M Apr 13 02:10 rootfs.ext2
lrwxrwxrwx 1 fugitive fugitive 11 Apr 13 01:01 rootfs.ext4 -> rootfs.ext2
-rw-r--r-- 1 fugitive fugitive 74M Apr 13 01:01 rootfs.iso9660
What my goal is - to create a bootabile iso image, but I don't know how.
I am able to emulate it with qemu, like you can see on the screenshot:
I've tried to burn rootfs.iso9660 to USB drive, but not able to boot.
Tried to rename rootfs.iso9660 to rootfs.iso9660.iso and try with VirtualBox, but then I got a grub terminal.
Appreciate the help and instructions!
EDIT:
.config file:
-bash-4.2$ grep BR2_TARGET_ROOTFS_ .config | grep -v ^#
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_CPIO_NONE=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_GEN=4
BR2_TARGET_ROOTFS_EXT2_REV=1
BR2_TARGET_ROOTFS_EXT2_LABEL=""
BR2_TARGET_ROOTFS_EXT2_BLOCKS=0
BR2_TARGET_ROOTFS_EXT2_INODES=0
BR2_TARGET_ROOTFS_EXT2_EXTRA_BLOCKS=0
BR2_TARGET_ROOTFS_EXT2_EXTRA_INODES=0
BR2_TARGET_ROOTFS_EXT2_RESBLKS=0
BR2_TARGET_ROOTFS_EXT2_NONE=y
BR2_TARGET_ROOTFS_ISO9660=y
BR2_TARGET_ROOTFS_ISO9660_GRUB2=y
BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="fs/iso9660/grub.cfg"
BR2_TARGET_ROOTFS_ISO9660_INITRD=y
-bash-4.2$ grep -r BR2_TARGET_ROOTFS_ISO9660_HYBRID *
fs/iso9660/Config.in:config BR2_TARGET_ROOTFS_ISO9660_HYBRID
fs/iso9660/iso9660.mk:ifeq ($(BR2_TARGET_ROOTFS_ISO9660_HYBRID),y)
Have you enabled BR2_TARGET_ROOTFS_ISO9660_HYBRID ? This is needed if you want your ISO image to also work from a USB device.
A bootable ISO image (old school ISO just for CDROMs) with Grub2 - I made it work.
The main hints:
Grub: add builtin modules biosdisk iso9660
Grub: boot partition set to cd
After changing Grub options you need to recompile it (read how to rebuild package in official manual)
If you do changes in kernel config, make sure that CDROM devices and ISO9660 filesystem are supported
If you are in grub rescue console (which is not a good sign), try to execute commands step by step (like in this answer) to figure out the issue.
Extract from .config
I saved my changes as defconfig (make savedefconfig, read here) and here is what you should have in yours:
BR2_ROOTFS_POST_BUILD_SCRIPT="board/pc/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="support/scripts/genimage.sh"
BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/pc/genimage-bios.cfg"
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
BR2_TARGET_ROOTFS_EXT2_SIZE="120M"
BR2_TARGET_ROOTFS_ISO9660=y
BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU="fs/iso9660/grub.cfg"
BR2_TARGET_GRUB2=y
BR2_TARGET_GRUB2_BOOT_PARTITION="cd"
BR2_TARGET_GRUB2_BUILTIN_MODULES="boot linux ext2 fat squash4 part_msdos part_gpt normal biosdisk iso9660"
BR2_PACKAGE_HOST_GENIMAGE=y
Side note: I started my trials with building a default configuration for PC make pc_x86_64_defconfig && make
Test
Test your ISO in QEMU:
qemu-system-x86_64 -m 512 -cdrom output/images/rootfs.iso9660
It also works in Virtual Box.
Try :
sudo dd if=/path/to/output/images/disk.img of=/path/to/usb/drive bs=1M
To know the path to your usb drive do :
lsblk
and find your usb drive.

Kernel defconfig in buildroot (arm target)

Debian 8 x64, buildroot 2016.02 / 2016-05-07 / 2016-05-13.
After make menuconfig and set some settings I run make. There is an error appears:
linux/linux.mk:424: *** No kernel defconfig name specified, check your
BR2_LINUX_KERNEL_DEFCONFIG setting. Stop.
This answer does not help: my arch/arm/configs/ folder does not exist in every release/snapshot I've tried. There is only arch folder with this content:
-rw-r--r-- 1 user user 11K May 12 19:21 Config.in
-rw-r--r-- 1 user user 176 May 12 19:21 Config.in.aarch64
-rw-r--r-- 1 user user 1.7K May 12 19:21 Config.in.arc
-rw-r--r-- 1 user user 15K May 12 19:21 Config.in.arm
-rw-r--r-- 1 user user 2.2K May 12 19:21 Config.in.bfin
-rw-r--r-- 1 user user 735 May 12 19:21 Config.in.m68k
-rw-r--r-- 1 user user 279 May 12 19:21 Config.in.microblaze
-rw-r--r-- 1 user user 2.1K May 12 19:21 Config.in.mips
-rw-r--r-- 1 user user 70 May 12 19:21 Config.in.nios2
-rw-r--r-- 1 user user 5.5K May 12 19:21 Config.in.powerpc
-rw-r--r-- 1 user user 693 May 12 19:21 Config.in.sh
-rw-r--r-- 1 user user 617 May 12 19:21 Config.in.sparc
-rw-r--r-- 1 user user 7.5K May 12 19:21 Config.in.x86
-rw-r--r-- 1 user user 1.5K May 12 19:21 Config.in.xtensa
I've tried to create arch/arm/configs/ folder and put there arch/Config.in.arm file (renamed to arm_defconfig/whatever) or empty file (renamed).
Whatever Kernel - Defconfig name I set, it does not helps.
make BR2_LINUX_KERNEL_DEFCONFIG also does not helps. Option is not documented in Buildroot user manual.
make linux-menuconfig returns same error if no Kernel - Defconfig name seted or
Can't find default configuration "arch/arm/configs/name_defconfig"!
where name is Kernel - Defconfig name variable. I've tried to set this to arm, BR2_LINUX_KERNEL_DEFCONFIG and many other names.
Can you help me, how to set default kernel configuration from buildroot developers?
The kernel defconfig is a configuration file in the kernel tree, not the buildroot tree. You have to look in arch/arm/configs in the kernel. Find the defconfig there that is appropriate for your target CPU. If you are not using an upstream kernel, you'll have to check with the vendor which defconfig to use. Remember to remove the _defconfig part of the name.
If you really have no idea at all, multi_v5 and multi_v7 are safe options: they include support for all possible processors with an ARMv5 resp. ARMv7 architecture.
You will probably encounter the same issue with the device tree. You can find the device trees (the .dts files) in arch/arm/boot/dts in the kernel tree. This one does have to match exactly with your board.

Access GPIO (/sys/class/gpio) as non-root

The /sys/class/gpio can only be accessed as root by default. So I like that a new group gpio can use the files and directories under /sys/class/gpio. To achieve that I added the following lines to /etc/rc.local (I'm on Debian):
sudo chown root:gpio /sys/class/gpio/unexport /sys/class/gpio/export
sudo chmod 220 /sys/class/gpio/unexport /sys/class/gpio/export
So this gives write permissions to all the gpio group members. So they can now export and unexport pins fine.
The problem is they can't read/write the specific pin files after export (e.x. /sys/class/gpio/gpio17) beacause those are owned by root:root again.
How can I change that they are created by default as root:gpio too? I mean I can do that manually each time I export a pin. But that's a bit uncomfy.
UPDATE
According to larsks' answer I created the missing rule file. Now it partially works:
-rwxrwx--- 1 root gpio 4096 Jun 19 16:48 export
lrwxrwxrwx 1 root gpio 0 Jun 19 16:51 gpio17 -> ../../devices/soc/3f200000.gpio/gpio/gpio17
lrwxrwxrwx 1 root gpio 0 Jun 19 16:45 gpiochip0 -> ../../devices/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4096 Jun 19 16:45 unexport
But for the ./gpio17/ I still get root:root:
-rw-r--r-- 1 root root 4096 Jun 19 16:52 active_low
lrwxrwxrwx 1 root root 0 Jun 19 16:52 device -> ../../../3f200000.gpio
-rw-r--r-- 1 root root 4096 Jun 19 16:52 direction
-rw-r--r-- 1 root root 4096 Jun 19 16:52 edge
drwxr-xr-x 2 root root 0 Jun 19 16:52 power
lrwxrwxrwx 1 root root 0 Jun 19 16:52 subsystem -> ../../../../../class/gpio
-rw-r--r-- 1 root root 4096 Jun 19 16:52 uevent
-rw-r--r-- 1 root root 4096 Jun 19 16:52 value
UPDATE 2
Okay I solved the problem. Because I installed Raspbian over the RaspbianInstaller I never went through the raspi-config tool. This seems to be a problem. Because I was also missing the /sys/device/virtual/gpio/ folder.
I followed this guide here: https://community.element14.com/products/raspberry-pi/f/forum/26425/piface-digital-2---setup-and-use#139528
And afterwards the permissions were correct (even for the pin-folders and their files value, direction, ...).
More common rule for 4.x kernels will be the following
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'find -L /sys/class/gpio/ -maxdepth 2 -exec chown root:gpio {} \; -exec chmod 770 {} \; || true'"
The rule in the initial answer will fail to chown the exported gpio if there's a symbolic link in the path
UPD please beg in mind that when you export some GPIO via sysfs, you should wait for udev rule to fire and complete before you get desired access rights. The thing that worked for me was sleep about 100ms before trying to access GPIO files.
You can do this using udev rules, which can define actions to execute when the kernel instantiates new devices. Current versions of the Raspbian distribution for Raspberry Pi devices contain the following in /etc/udev/rules.d/99-com.rules:
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio'"
This ensures that entries under /sys/class/gpio are always available to members of the gpio group:
# ls -lL /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 May 6 23:36 export
drwxrwx--- 2 root gpio 0 Jan 1 1970 gpiochip0
-rwxrwx--- 1 root gpio 4096 May 6 23:37 unexport
# echo 11 > /sys/class/gpio/export
# ls -lL /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 May 6 23:37 export
drwxrwx--- 2 root gpio 0 May 6 23:37 gpio11
drwxrwx--- 2 root gpio 0 Jan 1 1970 gpiochip0
-rwxrwx--- 1 root gpio 4096 May 6 23:37 unexport
Update
Permissions are correct for individual pins as well:
# ls -Ll /sys/class/gpio/gpio11/
total 0
-rwxrwx--- 1 root gpio 4096 May 6 23:37 active_low
drwxr-xr-x 3 root root 0 May 6 23:36 device
-rwxrwx--- 1 root gpio 4096 May 6 23:37 direction
-rwxrwx--- 1 root gpio 4096 May 6 23:37 edge
drwxrwx--- 2 root gpio 0 May 6 23:37 subsystem
-rwxrwx--- 1 root gpio 4096 May 6 23:37 uevent
-rwxrwx--- 1 root gpio 4096 May 6 23:37 value
Expanding on the answer by #roman-savrulin, here's a simpler version.
There's no need to run the rule on REMOVE events, only ADD events. There's also no need to run 'find' as the udev environment will supply the exact path of the sysfs directory containing the new GPIO pin's files. You can also use 'chgrp' to change only the owning group, and symbolic modes in 'chmod' to only add the group-write permission bit.
You'll still have to wait for the completion of the rule processing before trying to open the pin's files, but the process should complete more quickly with a simpler rule which only touches the minimum number of files necessary.
SUBSYSTEM=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chgrp -R gpio /sys/${DEVPATH} && chmod -R g+w /sys/${DEVPATH}'"
Check the groups you belong to:
userk#dopamine $: groups
userk sudo dialout
If you belong to dialout the following, if not, comment.
userk#dopamine $: ls -l /dev/gpiomem
crw------- root root /dev/gpiomem
This file mirrors the memory associated with the GPIO device. The output of the command means that the owner of the file is the root user and the group that "owns" it is the root group. The 10 characters represent the file type and the permissions associated with it. The current configuration allows the owner of the file to read and write to the file.
You want to be able to read and write that file if you want to control the gpios.
One option would be to modify the group owner and make it match with the one you belong to (dialout in my case) and set the permissions in order to allow all users of that group to read and write the file.
Long story short:
userk#dopamine $: sudo chown root:dialout /dev/gpiomem
userk#dopamine $: sudo chmod 660 /dev/gpiomem
Wait! This setting won't be persistent and will vanish after reboot.
See this post for further info about the topic
For Ubuntu run.
sudo apt install rpi.gpio-common

Use newsyslog to rotate log files, but only if they have a certain size

I'm on OS X 10.9.4 and trying to use newsyslog to rotate my app development log files.
More specifically, I want to rotate the files daily but only if they are not empty (newsyslog writes one or two lines to every logfile it rotates, so let's say I only want to rotate logs that are at least 1kb).
I created a file /etc/newsyslog.d/code.conf:
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/Users/manuel/code/**/log/*.log manuel:staff 644 7 1 $D0 GN
The way I understand the man page for the configuration file is that size and when conditions should work in combination, so logfiles should be rotated every night at midnight only if they are 1kb or larger.
Unfortunately this is not what happens. The log files are rotated every night, no matter if they only the rotation message from newsyslog or anything else:
~/code/myapp/log (master) $ ls
total 32
drwxr-xr-x 6 manuel staff 204B Aug 8 00:17 .
drwxr-xr-x 22 manuel staff 748B Jul 25 14:56 ..
-rw-r--r-- 1 manuel staff 64B Aug 8 00:17 development.log
-rw-r--r-- 1 manuel staff 153B Aug 8 00:17 development.log.0
~/code/myapp/log (master) $ cat development.log
Aug 8 00:17:41 localhost newsyslog[81858]: logfile turned over
~/code/myapp/log (master) $ cat development.log.0
Aug 7 00:45:17 Manuels-MacBook-Pro newsyslog[34434]: logfile turned over due to size>1K
Aug 8 00:17:41 localhost newsyslog[81858]: logfile turned over
Any tips on how to get this working would be appreciated!
What you're looking for (rotate files daily unless they haven't logged anything) isn't possible using newsyslog. The man page you referenced doesn't say anything about size and when being combined other than to say that if when isn't specified, than it is as-if only size was specified. The reality is that the log is rotated when either condition is met. If the utility is like its FreeBSD counterpart, it won't rotate logs less than 512 bytes in size unless the binary flag is set.
MacOS' newer replacement for newsyslog, ASL, also doesn't have the behavior you desire. As far as I know, the only utility which has this is logrotate using its notifempty configuration option. You can install logrotate on your Mac using Homebrew

Resources