libpruio (BB D/A - I/O fast and easy)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Dinosaur wrote:Edit: How are you getting the install.sh into memory to be able to paste it.
Are you linked to the laptop, or other method to read the file ?
I connect to the BBB from the PC by ssh: 'ssh debian@10.0.0.33', where 10.0.0.33 is the IP address of the BBB in my network, and debian is the user to log in. Then I type the commands for the BBB in the PC terminal. In order to paste the script contents into nano (running on BBB), I copy from the PC browser and paste it into the PC terminal (running nano on BBB) by pressing <shift>-<crtl>-V.

Currently I'm compressing the image. It takes some time. Also uploading will take some time. I'll send a mail when done.

Regards
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF

I just did the exact procedure that you described, with the only variant being the device name.
On my laptop the uSD is called sdc instead of mmcblk0

The other change is copying the script whilst the uSD is in my laptop.
Open the root folder as su and copy pruinstall.sh into it.

Then again as per your instruction on the BBB
All went without an error
BUT,cannot open /dev/uio5

How old is the BBB you are using ?

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Dinosaur wrote:How old is the BBB you are using ?
It's a 'rev c' with 4GB eMMC from 2016, I guess. But this shouldn't make any difference.

Obviously you didn't allow private mail in your user profile at this board. Please enable it, or send me a mail address.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Have enabled my PM as well
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Hi!

I managed to upload now to a public folder. So I can serve the link here. The image is called dino_8GB.xz located at

https://c.gmx.net/@329654446701156587/w ... AfSI5aNrTw

Use your PC browser to download the image, insert a uSD (assuming it's /dev/sdc), and change in a terminal to the download folder and execute

Code: Select all

$ sha256sum dino_8GB.xz 
8734bd22e5899a0ae5c1b29a3ef5396e5bdfd77ee8e958bd13f7b3d775463da1  dino_8GB.xz
$ xzcat dino_8GB.xz  | sudo dd status=progress of=/dev/sdc
Since I made a mistake while extracting my uSD this will write 8GB, and your uSD has to be at last 8GB as well, and the process is longer than necessary, sorry :-( Afterwards boot the BBB from that uSD and log in (debian/temppwd).

I cross-checked these steps. Here I get

Code: Select all

$ ls -l /dev/uio*
crw-rw---- 1 root users 243, 0 Feb 22 16:05 /dev/uio0
crw-rw---- 1 root users 243, 1 Feb 22 16:05 /dev/uio1
crw-rw---- 1 root users 243, 2 Feb 22 16:05 /dev/uio2
crw-rw---- 1 root users 243, 3 Feb 22 16:05 /dev/uio3
crw-rw---- 1 root users 243, 4 Feb 22 16:05 /dev/uio4
crw-rw---- 1 root users 243, 5 Feb 22 16:05 /dev/uio5
crw-rw---- 1 root users 243, 6 Feb 22 16:05 /dev/uio6
crw-rw---- 1 root users 243, 7 Feb 22 16:05 /dev/uio7
$ projects/examples/sos
watch SOS code on user LED 3 (near ethernet connector)

execute the following command to get rid of mmc1 triggers
  sudo su && echo none > /sys/class/leds/beaglebone:green:usr3/trigger && echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness && exit

press any key to quit
SOS   
Please report.

Regards
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF

Downloaded the file and followed the instructions to confirm the checksum and wrote a uSD.
Put it into the BBB to boot and got the little Penguin and a flashing cursor.
Left it for 5 minutes, and then powered down to try again with the same result.

I will now try another uSD and use different method of writing the uSD.
ie: Etcher or what I have done for many years.

Code: Select all

sudo dd of=/dev/sdc if=dino_8GB.xz
What method did you use to READ the uSD into an image.
Will let you know how I go.
Maybe I need to "Restore the BBB" and then wipe the emmcblk the way you suggested.
At the moment that area of the BBB is totally inaccessible.

Regards

EDIT: Etcher hung my computer at 27 %, that has never happened to me before.
EDIT2: extracted the image file from the .xz file and wrote it to uSD with dd and now it boots.
first and only thing I did was:
ls -l /dev/uio*
ls:cannot access '/dev/uio*': No such file or device.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Dinosaur wrote:Downloaded the file and followed the instructions to confirm the checksum and wrote a uSD.
Put it into the BBB to boot and got the little Penguin and a flashing cursor.
Left it for 5 minutes, and then powered down to try again with the same result.
Here is a login prompt after ~15 sec. As I said, I don't use a keyboard. Instead I've an ethernet connection to my network and log in from PC by ssh. But for you I connected a monitor: after the Tux there's a text message, the login prompt and a blinking cursor.

It seems that your system has no clean uSD boot. This looks like anything from eMMC disturbs the boot process. Make a further try and press the boot button on the board. Or, better than pressing the uSD boot button is to use a cable to connect pins P8_01 and P8_43 while booting. (The little button on the board is not easy to handle.) Release the cable when the LEDs start to blink.
Dinosaur wrote:I will now try another uSD and use different method of writing the uSD.
ie: Etcher or what I have done for many years.

Code: Select all

sudo dd of=/dev/sdc if=dino_8GB.xz
This wont work!!! The file dino_8GB.xz is compressed. You'll have to decompress first

Code: Select all

xzcat dino_8GB.xz > image.bin
sudo dd if=image.bin of=/dev/sdc
The command above does these two steps in one, using a pipe instead of an intermediate file.
Dinosaur wrote:What method did you use to READ the uSD into an image.
I used dd to read the uSD. But I was too lazy to specify the size, so I used

Code: Select all

sudo dd if=/dev/mmcblk0 | xz > dino_8GB.zx
Instead I should have used

Code: Select all

sudo dd if=/dev/mmcblk0 bs=1M count=2G iflag=count_bytes status=progress | xz > dino_2GB.xz
At your place I wouldn't change anything at this uSD. Instead I'd care about the BBB and its eMMC.
Dinosaur wrote:Will let you know how I go.
Maybe I need to "Restore the BBB" and then wipe the emmcblk the way you suggested.
At the moment that area of the BBB is totally inaccessible.
It doesn't make sense to restore and then override the restored setup. Just care about a clean wipe out.

I thought you did already wipe the eMMC. Perhaps you should wipe more than the boot sector, ie. sudo dd if=/dev/zero bs=512 count=1024 of=/dev/mmcblk1 (after booting from uSD -> check the disc size by df -h to erase the right drive).

Your first issue is to get the system running again. I recommend to have at least two uSD. One with a fresh original image for emergency boots.

Regards
Last edited by TJF on Feb 22, 2019 20:23, edited 1 time in total.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF
Make a further try and press the boot button on the board.
I already tried that.
(The little button on the board is not easy to handle.)
I use a pencil with a rubber on the end.
This wont work!!! The file dino_8GB.xz is compressed. You'll have to decompress first
Extracted it first and added the .img extension. That is the image I finally got booting.
I have to admit, I am impatient with any form of dd, and as such I do other things on the laptop whilst that is happening.
Will try your procedure again and have a snooze whilst it is writing.
I thought you did already wipe the eMMC.
Yes I did, but by simply deleting every file on it.

I have 2 uSD, so am rotating between them.

Have to take wife to Airport tomorrow, so will try some today and then get back to you by Monday.

Many thanks for all the effort you are putting in.
Hopefully at the end of this we have a documented procedure for others to use.

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Dinosaur wrote:Yes I did, but by simply deleting every file on it.
This is the problem, I guess. The kernel finds a valid drive system on eMMC and binds it as /dev/mmcblk0 in this case.

Instead it should bind the uSD as /dev/mmcblk0, and completly boot from uSD. You'll have to erase the partition table so that the kernel cannot bind this drive! I recommend
  • create a uSD with an original image that boots
  • boot form uSD and login as usual by debian/temppwd
  • check for the 4GB eMMC with command df -h (either /dev/mmcblk0 or /dev/mmcblk1)
  • then erase the first sectors on eMMC by executing (addapt the correct number [0|1])

Code: Select all

sudo dd if=/dev/zero bs=512 count=1024 of=/dev/mmcblk0
Dinosaur wrote:Hopefully at the end of this we have a documented procedure for others to use.
Sorry, your problems are not typical. This will help only you :-)

Regards

PS: Later, you can simply restore the eMMC with any bootable uSD image, where you uncomment the last line in file /boot/uEnv.txt. When the line 'cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh' is active, then the system doesn't boot. Instead it burns the uSD image on to the eMMC (takes about 10 minutes) and then reboots. (Note: this needs good power supply by 5V power jack, don't try with micro USB powering.)
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF

Finally SUCCESS.

Writing a new uSD with the .xz file ,without doing anything else on that computer; created a bootable drive.
When I then
sudo dd if=/dev/zero bs=512 count=1024 of=/dev/mmcblk1
it took only seconds.
Previously when I tried that , I aborted after 30 minutes. ??

Now sos works.

Will be in touch.

Regards

PS: I have had SOS as the ringtone on my iPhone for some years now.
45 years ago I connected an old Navy radio to my Z80 motherboard and wrote a morse code translation program that displayed english on the screen.
Found out years later that listening in on the Navy was highly illegal, but sure got some interesting stories when trainees started using the ship log.
Last edited by Dinosaur on Feb 22, 2019 21:32, edited 1 time in total.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Congrats!
Dinosaur wrote:When I then
sudo dd if=/dev/zero bs=512 count=1024 of=/dev/mmcblk1
it took only seconds
Hopefuly you erased the eMMC, and not the uSD. Anyway, you'll find out in next boot.

I prepared just the sos.bas example. You should be able to compile and check out the others as well. Especially the ones with pinmuxing (ie. button2.bas or pwm_cap.bas). They should work from debian user space (without sudo).

For graphical output (ie. oszi.bas) you wont need a desktop. Instead it's sufficient to install the frame buffer 'sudo apt install xserver-xorg-video-fbdev'.

Have fun, caring about the real issues!
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF

FYI
I have installed the library successfully in the Desktop Debian "Stretch" and found that the same script works there.
The only desktop application that is painfully slow is Synaptic, so I skip using that.
Bootup from first press of power button till full desktop is 85 seconds.

Applications installed:
GEdit , Geany , xChm , NetSurf (its really quick) , NitroShare (1 click file sharing with Eth crossover)
and a few minor support programs.

I am just about ready to start learning the use of your library.(one step at the time)

One question, what is the purpose / history behind these lines in the script ?
echo "renaming cape_universal overlay blob"
cd dtbs/`uname -r`
mv am335x-boneblack-uboot-univ.dtb am335x-boneblack-uboot-univ.dtb.org

Code: Select all

#!/bin/bash
clear
echo "Script to install libpruio & freebasic on Beaglebone Black"

echo "deb http://beagle.tuks.nl/debian jessie/" > /etc/apt/sources.list.d/tuks.list

echo "deb-src http://beagle.tuks.nl/debian jessie/" >> /etc/apt/sources.list.d/tuks.list

echo "wget"
wget -qO - http://beagle.tuks.nl/debian/pubring.gpg | sudo apt-key add -

echo "Update"
apt-get update

echo "Install FreeBasic"
apt-get install freebasic libncurses-dev

echo "Install Libpruio"
apt-get install libpruio-bas libpruio-dev libpruio-lkm libpruio-doc
adduser debian pruio

echo "cd "
cd /home/debian

echo "mkdir projects"
mkdir projects

echo "cd projects"
cd projects

echo "copy examples to projects"
cp -r /usr/share/doc/libpruio-bas/examples .
chown -R debian:debian examples

echo "generate new /boot/uEnv.txt"
cd /boot
mv uEnv.txt `date '+%F-%T'`_uEnv.txt
echo "uname_r="`uname -r` > uEnv.txt
echo "enable_uboot_overlays=1" >> uEnv.txt
echo "uboot_overlay_pru=/lib/firmware/AM335X-PRU-UIO-00A0.dtbo" >> uEnv.txt
echo "cmdline=coherent_pool=1M net.ifnames=0 quiet" >> uEnv.txt

echo "renaming cape_universal overlay blob"
cd dtbs/`uname -r`
mv am335x-boneblack-uboot-univ.dtb am335x-boneblack-uboot-univ.dtb.org

echo "Enter to reboot"
read 
sudo reboot
Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Hi!
Dinosaur wrote:One question, what is the purpose / history behind these lines in the script ?
Long story:

In early LINUX versions the kernel gets compiled for a specific board. This means ie. the BBB needs another kernel than the RPi, allthough they have the same architecture armhf.

Today the hardware configuration isn't inbuild in the kernel any more. Instead the kernel loads a file that describes the hardware configuration, which is called the device tree. And the kernel can complement the existing device tree by further parts, described in a device tree blob (a subset of the full device tree).

This blob method is used by the standard pinmuxing system on BBB. The cape universal blob pre-declares some pin configurations (ie. GPIO-IN-pullup, GPIO-IN-pulldown, GPIO-OUT-nopull, ... and also PWM, SPI, ...). Later, the user can switch between the pre-declared pinmuxing modes (since kernel 4.14 also from user space) by a tool called config-pin.

This method has a lot of downsides:
  • The user can choose only pre-defined configurations. Ie. Fast PRU-GPIO with pull up or down resistor isn't pre defined. And a lot of others are missing.
  • It needs a separat tool to choose the pinmuxing mode (multiple source).
  • The tool is unsave. By miss-configuration you can damage the CPU.
  • Each declaration needs memory in kernel space and boot time (this blob is approx. three times bigger than the hardware blob, and still incomplete).
  • The device tree compiler has a lot of bugs and cannot create big blobs containing a full set of possibilities (it fails without warning or error message).
From my point of view this is experimental stuff. In libpruio I realized a solution where the user can set all possible (and impossible) pinmuxing modes. The memory footprint is pretty small (3k/16k for the LKM). All configurations get done by single source in the users code. The solution is faster and safer than the external tool.

But there is no way to make my system compatible to the default. When the standard stuff gets triggered by file /boot/dtbs/`uname -r`/am335x-boneblack-uboot-univ.dtb, then all pins get claimed by that device tree blob. libpruio respects these claims and doesn't override pinmuxing mode for the claimed pins. (You can drop this safety feature, but you'll end up with a code that also can override important system functions, ie. like on-board power management -> not good for beginners).

Renaming that trigger file disables the default pinmuxing system. That saves boot time and kernel memory, and frees the pins for simple use by libpruio. (Unfortunately the main stream developers didn't implement a solution to fully disable the system: P9_19 and P9_20 are still claimed and can only get freed when you disable all uBoot device tree blob loading.)

Regards

PS: 85 sec. for a desktop boot seems to be pretty slow. I remember boot times in the 30 sec. area. But I follow a converse strategy. I don't install everytihing and switch of single features later. Instead I install only the necessary parts.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: libpruio (BB D/A - I/O fast and easy)

Post by Dinosaur »

Hi TJF

Many thanks for that detailed explanation, perhaps I didn't understand it fully, but enough to leave it be.

Can you explain how to use the documentation for the library on the development platform please.
I don't want to go on line each time.

Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: libpruio (BB D/A - I/O fast and easy)

Post by TJF »

Hi Dinosaur

The HTML tree on the box with the installed libpruio-doc package starts at (Debian standard)

/usr/share/doc/libpruio-doc/html/index.html

Use your preferred browser to view the contents.

Regards
Post Reply