WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Porting piCore 8.0 -> BeagleBone Black  (Read 619 times)

Offline bugger553

  • WikiUser
  • *
  • Posts: 4
Porting piCore 8.0 -> BeagleBone Black
« on: November 04, 2016, 04:32:03 AM »
Hello everybody,

Currently I am porting the latest piCore (v8.0) to Beaglebone Black. Now I am encountering a weird issue:
When "tc-config" is running, it fails to mount/install the tce/optional extensions. I tried to debug with appending "showapps" to CMDLINE, it fails with following error:
Code: newbielink:javascript:void(0); [nonactive]
Booting Core 8.0
Running Linux Kernel 4.4.27-ti-r62.
Checking boot options... Done.
Starting udev daemon for hotplug support... Done.
Scanning hard disk partitions to create /etc/fstab
Setting Language to C Done.
Skipping rtc as requested from the boot command line.
Possible swap partition(s) enabled.
Loading extensions...
Traceback (most recent call last):
  File "/usr/bin/tce-bootload", line 15, in <module>
OSError: [Errno 13] EACCES
 Done.
Setting keymap to us Done.
Restoring backup files from /mnt/mmcblk0p2/tce/mydata.tgz -
Done.

Either way, when I get dropped to (serial) shell .. modules "loop", "zram" and "squashfs" are loaded (as MODULE from initrd).. and I can load and start extensions via "tce-load -i <package_location>" without issues. Just the auto-loading *onboot* is not working

Here is what I did to create the image:
Code: newbielink:javascript:void(0); [nonactive]
#!/bin/bash

SECT_SIZE=512
DEPMOD="/tmp/depmod.pl"
BASEDIR="/tmp/rb"

ORIG_INITRD_PI_NAME="8.0v7.gz"

BONE_IMG="/tmp/bone-debian-8.6-console-armhf-2016-10-30-2gb.img"
PICORE_IMG="/tmp/piCore_8.0.img"

BBB_START_SECT="8192"
PICORE_PART1_START_SECT="2048"
PICORE_PART2_START_SECT="53248"


BONE_BASE_MNT="/tmp/rb/mnt/bone"
PICORE_BASE_MNT="/tmp/rb/mnt/picore"

MNT_ROOTFS="rootfs"

INITRD_BBB_TMPDIR="/tmp/rb/initrd_bbb"
INITRD_PICORE_TMPDIR="/tmp/rb/initrd_pi"
INITRD_OUTPUT_TMPDIR="/tmp/rb/initrd_out"

MYDATA_TMPDIR="/tmp/rb/mydata_tmp"

OUTPUT_DIR="/tmp/rb/output"

if [ ! -f "$BONE_IMG" ]
then
    echo "[-] Input BBB image $BONE_IMG not found!"
    exit 0
fi

if [ ! -f "$PICORE_IMG" ]
then
    echo "[-] Input BBB image $BONE_IMG not found!"
    exit 0
fi

echo "[+] Creating output directories"
mkdir -p $OUTPUT_DIR/boot &> /dev/null

echo "[+] Ensuring output directories are clean.. (If you didnt save.. you just lost!)"
rm -R $OUTPUT_DIR/boot/* &> /dev/null
rm -R $OUTPUT_DIR/rootfs/* &> /dev/null

echo "[+] Creating mount points..."
mkdir -p $BONE_BASE_MNT/rootfs &> /dev/null || echo "[-] $BONE_BASE_MNT/rootfs already exists..."

mkdir -p $PICORE_BASE_MNT/boot &> /dev/null || echo "[-] $BONE_BASE_MNT/boot already exists..."
mkdir -p $PICORE_BASE_MNT/rootfs &> /dev/null || echo "[-] $PICORE_BASE_MNT/rootfs already exists..."

echo "[+] Making sure nothing is mounted there currently"
umount $BONE_BASE_MNT/rootfs &> /dev/null
umount $PICORE_BASE_MNT/boot &> /dev/null
umount $PICORE_BASE_MNT/rootfs &> /dev/null

echo "[+] Mounting the images"
mount $BONE_IMG $BONE_BASE_MNT/rootfs -o offset=$(($SECT_SIZE * $BBB_START_SECT)) || echo "[-] Failed to mount rootfs from BBB image..." | exit 0
mount $PICORE_IMG $PICORE_BASE_MNT/boot -o offset=$(($SECT_SIZE * $PICORE_PART1_START_SECT)) || echo "[-] Failed to mount boot from piCore image..." | exit 0
mount $PICORE_IMG $PICORE_BASE_MNT/rootfs -o offset=$(($SECT_SIZE * $PICORE_PART2_START_SECT)) || echo "[-] Failed to mount rootfs from piCore image..." | exit 0

BONE_KERNEL=$(ls "$BONE_BASE_MNT/rootfs/lib/modules/")
echo "[+] Bone Kernel Version: $BONE_KERNEL"

echo "[+] Copying uEnv and boot file from bbb image to output-dir"
cp $BONE_BASE_MNT/rootfs/uEnv.txt $OUTPUT_DIR/boot/
cp -r $BONE_BASE_MNT/rootfs/boot $OUTPUT_DIR/boot/

echo "# Add nortc to cmdline.. and change root=/dev/mmc... -> root=\${mmcroot}" >> "$OUTPUT_DIR/boot/uEnv.txt"
vi $OUTPUT_DIR/boot/uEnv.txt

echo "[+] Verifying file layout"
if [ ! -f $OUTPUT_DIR/boot/uEnv.txt ]
then
    echo "[-] File not found: $OUTPUT_DIR/boot/uEnv.txt ... Aborting!"
    exit 0
fi

if [ ! -f $OUTPUT_DIR/boot/boot/initrd.img-$BONE_KERNEL ]
then
    echo "[-] File not found: $OUTPUT_DIR/boot/boot/initrd.img-$BONE_KERNEL ... Aborting!"
    exit 0
fi

if [ ! -f $PICORE_BASE_MNT/boot/$ORIG_INITRD_PI_NAME ]
then
    echo "[-] File not found: $PICORE_BASE_MNT/boot/$ORIG_INITRD_PI_NAME ... Aborting!"
    exit 0
fi

echo "[+] Copying Initrd to temp-dir for modification"
cp $PICORE_BASE_MNT/boot/$ORIG_INITRD_PI_NAME $BASEDIR/initrd_pi.cpio.gz || echo "[-] Failed to copy piCore Initrd..." | exit 0
cp $OUTPUT_DIR/boot/boot/initrd.img-$BONE_KERNEL $BASEDIR/initrd_bbb.cpio.gz || echo "[-] Failed to copy BBB Initrd..." | exit 0

echo "[+] Unpacking Initrds..."
rm -Rf $INITRD_BBB_TMPDIR &> /dev/null
rm -Rf $INITRD_PICORE_TMPDIR &> /dev/null
mkdir -p $INITRD_BBB_TMPDIR &> /dev/null
mkdir -p $INITRD_PICORE_TMPDIR &> /dev/null

cd "$INITRD_BBB_TMPDIR"
gunzip -c "$BASEDIR/initrd_bbb.cpio.gz" | cpio -imd
cd "$INITRD_PICORE_TMPDIR"
gunzip -c "$BASEDIR/initrd_pi.cpio.gz" | cpio -imd

echo "[+] Assembling new initrd"
rm -rf $INITRD_OUTPUT_TMPDIR &> /dev/null

cp -r $INITRD_PICORE_TMPDIR $INITRD_OUTPUT_TMPDIR
rm -rf $INITRD_OUTPUT_TMPDIR/lib/modules/*
cp -r $INITRD_BBB_TMPDIR/lib/modules/$BONE_KERNEL $INITRD_OUTPUT_TMPDIR/lib/modules/$BONE_KERNEL

echo "[+] Copying additional squashfs module..."
mkdir -p $INITRD_OUTPUT_TMPDIR/lib/modules/$BONE_KERNEL/kernel/fs/squashfs
cp -r $BONE_BASE_MNT/rootfs/lib/modules/$BONE_KERNEL/kernel/fs/squashfs/squashfs.ko $INITRD_OUTPUT_TMPDIR/lib/modules/$BONE_KERNEL/kernel/fs/squashfs

echo "[+] Symlinking modules"
rm -rf $INITRD_OUTPUT_TMPDIR/usr/local/lib/modules/$BONE_KERNEL
ln -s /lib/modules/$BONE_KERNEL $INITRD_OUTPUT_TMPDIR/usr/local/lib/modules/$BONE_KERNEL
ln -s /lib/modules/$BONE_KERNEL/kernel $INITRD_OUTPUT_TMPDIR/lib/modules/$BONE_KERNEL/kernel.tclocal

echo "[+] Please edit /usr/sbin/startserialtty according to your serial interface"
vi $INITRD_OUTPUT_TMPDIR/usr/sbin/startserialtty

echo "[+] Running depmod in chroot"
$DEPMOD -F $OUTPUT_DIR/boot/boot/System.map-$BONE_KERNEL -b $INITRD_OUTPUT_TMPDIR/lib/modules > $INITRD_OUTPUT_TMPDIR/lib/modules/$BONE_KERNEL/modules.dep

echo "[+] Repacking initrds..."
cd $INITRD_OUTPUT_TMPDIR
find . | cpio -o -H newc | gzip > $OUTPUT_DIR/initrd.gz
cp $OUTPUT_DIR/initrd.gz $OUTPUT_DIR/boot/boot/initrd.img-$BONE_KERNEL

echo "[+] Copying rootfs"
cp -r $PICORE_BASE_MNT/rootfs $OUTPUT_DIR/

echo "[+] Unmounting everything ... now that we are done..."
umount $BONE_BASE_MNT/rootfs &> /dev/null
umount $PICORE_BASE_MNT/boot &> /dev/null
umount $PICORE_BASE_MNT/rootfs &> /dev/null

echo "[+] Now please create an skeleton image, 2 partitions (1: FAT, 2: EXT4) and copy $OUTPUT_DIR/[boot, rootfs] accordingly"

# TODO: Automate partition-detection for input-images
# TODO: Create *-modules-KERNEL.tcz for audio and wireless
# TODO: Copy filesystem to dd-able img
# TODO: Some sed-action to fix up config files automatically without user-input

exit 0

Are there any nice ways to properly debug this issue? Did I miss something?

P.S: Please be kind, it's my first bigger shell script. Thanks!
« Last Edit: November 04, 2016, 04:34:51 AM by bugger553 »

Online bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 6897
    • My Community Forum
Re: Porting piCore 8.0 -> BeagleBone Black
« Reply #1 on: November 04, 2016, 06:19:29 AM »
Quote
SError: [Errno 13] EACCES

It is a MicroPython error message, access denied which indicates a permission error.

Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline bugger553

  • WikiUser
  • *
  • Posts: 4
Re: Porting piCore 8.0 -> BeagleBone Black
« Reply #2 on: November 04, 2016, 06:53:50 AM »
Yeah, Its trying to create a file in */var/log/* - Isn't that world writable normally?

Offline bugger553

  • WikiUser
  • *
  • Posts: 4
Re: Porting piCore 8.0 -> BeagleBone Black
« Reply #3 on: November 04, 2016, 11:02:42 AM »
Hmm I cannot edit my previous post:

ISSUE FIXED: Stupid mistake, permission problem: Did not use cp -ra to preserve permissions, only used cp -r

You can find the finished script attached