Page 1 of 1

M4 : update kernel and dtb files

Posted: Mon Mar 16, 2020 11:43 pm
by GoblE
Hi,

I'm user of this very good board which is NanoPi M4.
I would like to add CAN-BUS support to the friendlyCore image by updating kernel, dtb and modules files of my current SDcard.

Problem that I have : I don't understand how I can replace current files of my SDcard, without reflasing all the SDcard (eflasher) ? I saw "linux upgrade tool" too, but I can't see information about dtb file.

I checked uboot, but I only saw address without clear location. I suspect files are stored into the raw partition of the SDcard.

If you have solution to replace kernel and dtb file I'm interested.

Thank you.

Re: M4 : update kernel and dtb files

Posted: Fri Mar 20, 2020 11:17 pm
by GoblE
Nobody know where are stored and how we can do to update kernel and dtb files of the rk3399-sd-friendlycore-bionic-4.4-arm64 image ?

Re: M4 : update kernel and dtb files

Posted: Sat Mar 21, 2020 9:12 am
by igorp
GoblE wrote:
Nobody know where are stored and how we can do to update kernel and dtb files of the rk3399-sd-friendlycore-bionic-4.4-arm64 image ?


With Armbian playing with this its easier.

https://forum.armbian.com/topic/13347-n ... ment-97310
https://forum.armbian.com/topic/13389-s ... ment-97352

Re: M4 : update kernel and dtb files

Posted: Sat Mar 21, 2020 10:25 am
by GoblE
igorp wrote:
GoblE wrote:
Nobody know where are stored and how we can do to update kernel and dtb files of the rk3399-sd-friendlycore-bionic-4.4-arm64 image ?


With Armbian playing with this its easier.

https://forum.armbian.com/topic/13347-n ... ment-97310
https://forum.armbian.com/topic/13389-s ... ment-97352



Thank you for your help igorp!
Nice mechanism, unfortunately is not the same with friendlycore image :cry:
Kernel and dtb files seem to be stored in the sdcard, but where....

Re: M4 : update kernel and dtb files

Posted: Sat Mar 21, 2020 11:31 am
by igorp
GoblE wrote:
Thank you for your help igorp!
Nice mechanism, unfortunately is not the same with friendlycore image :cry:


Armbian support is much better and there are more people which can help you.

https://docs.armbian.com/#what-is-armbian

GoblE wrote:
Kernel and dtb files seem to be stored in the sdcard, but where....


I only tried this once, probably on separate partition.

Re: M4 : update kernel and dtb files

Posted: Sun Mar 22, 2020 10:05 pm
by GoblE
igorp wrote:
Armbian support is much better and there are more people which can help you.
https://docs.armbian.com/#what-is-armbian

Ok, I did lot of things on my current image so I'll try to find a solution but it's good thing to know for the future, before to start an embedded development. thanks for your feedback igorp.

igorp wrote:
I only tried this once, probably on separate partition.

Yes, I think too. I suspect that the first "unused" memory area contains raw data :
sd_friendlycore.png
sd_friendlycore.png (47.75 KiB) Viewed 15220 times

Re: M4 : update kernel and dtb files

Posted: Sun Mar 22, 2020 10:11 pm
by igorp
GoblE wrote:
I did lot of things on my current image


Currently you are not receiving any updates. Not functional nor security for the most important part. That doesn't bothers you?

Re: M4 : update kernel and dtb files

Posted: Mon Mar 23, 2020 12:06 am
by GoblE
igorp wrote:
GoblE wrote:
I did lot of things on my current image


Currently you are not receiving any updates. Not functional nor security for the most important part. That doesn't bothers you?

For my current use case no, it's a POC, not connected to the web. If this kernel information was not missing, my POC would be finished :|

Re: M4 : update kernel and dtb files

Posted: Wed Mar 25, 2020 10:55 pm
by GoblE
Ok I found the solution! Based on provided scripts from FriendlyARM (sd-fuse_rk3399), I made this script to flash parameters, kernel and dtb files only into the first raw partition.

I copied usefull files next to my script :
- kernel.img (kernel binary)
- resource.img (dtb, logo, etc)
- param4sd.txt (from sd-fuse_rk3399 repo)
- parameter.txt (from sd-fuse_rk3399 repo)
- partmap.txt (from sd-fuse_rk3399 repo)
- sd_update (from sd-fuse_rk3399 repo)

Code: Select all

#!/bin/bash
# flash=mmc,1:kern:raw:0x2000000,0x2000000:kernel.img;
# flash=mmc,1:boot:raw:0x4000000,0x2000000:boot.img;

# Checking device for fusing
if [ $# -eq 0 ]; then
   echo "Usage: $0 DEVICE"
   exit 0
fi

case $1 in
/dev/sd[a-z] | /dev/loop[0-9]* | /dev/mmcblk[0-9]*)
   if [ ! -e $1 ]; then
      echo "Error: $1 does not exist."
      exit 1
   fi
   DEV_NAME=`basename $1`
   BLOCK_CNT=`cat /sys/block/${DEV_NAME}/size` ;;&
/dev/sd[a-z])
   DEV_PART=${DEV_NAME}1
   REMOVABLE=`cat /sys/block/${DEV_NAME}/removable` ;;
/dev/mmcblk[0-9]* | /dev/loop[0-9]*)
   DEV_PART=${DEV_NAME}p1
   REMOVABLE=1 ;;
*)
   echo "Error: Unsupported SD reader"
   exit 0
esac

if [ ${REMOVABLE} -le 0 ]; then
   echo "Error: $1 is a non-removable device. Stop."
   exit 1
fi

if [ -z ${BLOCK_CNT} -o ${BLOCK_CNT} -le 0 ]; then
   echo "Error: $1 is inaccessible. Stop fusing now!"
   exit 1
fi

let DEV_SIZE=${BLOCK_CNT}/2
if [ ${DEV_SIZE} -gt 64000000 ]; then
   echo "Error: $1 size (${DEV_SIZE} KB) is too large"
   exit 1
fi

true ${MIN_SIZE:=600000}
if [ ${DEV_SIZE} -le ${MIN_SIZE} ]; then
    echo "Error: $1 size (${DEV_SIZE} KB) is too small"
    echo "       please try another SD card."
    exit 1
fi

# ----------------------------------------------------------
cp ../kernel-rockchip/*.img $(dirname $0)

# ----------------------------------------------------------
RKPARAM=$(dirname $0)/parameter.txt
RKPARAM2=$(dirname $0)/param4sd.txt

# Automatically re-run script under sudo if not root
if [ $(id -u) -ne 0 ]; then
   echo "Need sudo..."
   sudo "$0" "$@"
fi

# ----------------------------------------------------------
# Get host machine
ARCH=
if uname -mpi | grep aarch64 >/dev/null; then
   ARCH=aarch64/
fi

# ----------------------------------------------------------
# umount all at first
umount /dev/${DEV_NAME}* > /dev/null 2>&1
sync

# ----------------------------------------------------------
# partition card & fusing filesystem
true ${SD_UPDATE:=$(dirname $0)/sd_update}

[[ ! -f "${RKPARAM}" ]] && exit 0

PARTMAP=$(dirname $0)/partmap.txt
PARAM4SD=$(dirname $0)/param4sd.txt

# ----------------------------------------------------------
# Prepare image for sd raw img
#     emmc boot: need parameter.txt, do not need partmap.txt
#     sdraw: all need parameter.txt and partmap.txt
if [ ! -f "${PARTMAP}" ]; then
      echo "File not found: ${PARTMAP}, please download the latest version of the image files from http://dl.friendlyarm.com/nanopct4"
      exit 1
fi

if [ ! -f "${PARAM4SD}" ]; then
      echo "File not found: ${PARAM4SD}, please download the latest version of the image files from http://dl.friendlyarm.com/nanopct4"
      exit 1
fi

# write ext4 image
${SD_UPDATE} -d /dev/${DEV_NAME} -p ${PARTMAP}
if [ $? -ne 0 ]; then
   echo "Error: filesystem fusing failed, Stop."
   exit 1
fi

if [ -z ${ARCH} ]; then
   partprobe /dev/${DEV_NAME} -s 2>/dev/null
fi
if [ $? -ne 0 ]; then
   echo "Warning: Re-reading the partition table failed"

else
  sleep 1
  resize2fs -f /dev/${DEV_PART}
fi

sync
echo "---------------------------------"
echo "All done."