Debian Kernel Marvel Kirkwood


Primeiramente gostaria de salientar que não sou o autor principal do conteúdo deste artigo. A minha intenção é de mostrar o que outros autores tem realizado (referenciando links para o conteúdo original) neste blog até como um guia pessoal para uso próprio e ainda compartilhar minhas anotações e pequenas modificações que realizo no conteúdo, desejando que possa ajudar mais alguém em algum lugar.
First and foremost, I take no credit for any of this post’s content. I am really just taking what others have done (which I have links to bellow) and am putting it on my blog for a personal reference and hopefully the small changes that I made to their guides will help someone somewhere.


link: https://github.com/daniviga/ix2-200

link: https://www.howtoforge.com/kernel_compilation_debian_etch#how-to-compile-a-kernel-debian-etch-

Montando uma Máquina Virtual para compilar o Kernel


sudo lxc-create -t debian -n crossjessie -- -r jessie -a i686
sudo lxc-stop -n crossjessie --kill
sudo chroot /var/lib/lxc/crossjessie/rootfs
apt-get install sysvinit-core curl nano
exit
echo "lxc.aa_profile = unconfined" | sudo tee -a /var/lib/lxc/crossjessie/config

Para executar um comando direto no container sem entrar em um console:
sudo lxc-start -d -n crossjessie
sudo lxc-attach -n crossjessie -- apt-get update

Para iniciar a máquina virtual e um console no container:
sudo lxc-start -d -n crossjessie
sudo lxc-console -n crossjessie -t 1

Preste atenção nas instruções abaixo:
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself
o usuário root tem a senha root

nano /etc/apt/sources.list
deb http://http.debian.net/debian          jessie         main contrib non-free
deb http://http.debian.net/debian          unstable         main contrib non-free
deb http://security.debian.org/ jessie/updates main contrib non-free
deb http://emdebian.org/tools/debian/ jessie  main
deb http://emdebian.org/tools/debian/ unstable  main
deb-src http://ftp.br.debian.org/debian/ jessie main contrib non-free
deb-src http://ftp.br.debian.org/debian/ unstable main contrib non-free

curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add -

nano /etc/apt/preferences.d/main
Package: * 
Pin: release a=stable 
Pin-Priority: 900

Package: *
Pin: release a=jessie
Pin-Priority: 600

Package: * 
Pin: release a=unstable 
Pin-Priority: 100

nano /etc/apt/apt.conf.d/70debconf
// Pre-configure all packages with debconf before they are installed.
// If you don't like it, comment it out.
DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt || true";};
APT::Default-Release "jessie";

dpkg --add-architecture armel 
apt-get update
apt-get install wget devscripts crossbuild-essential-armel kernel-package gcc-arm-linux-gnueabi ncurses-dev u-boot-tools sshpass xz-utils fakeroot

Obtendo o codigo fonte

apt-get  install -t unstable linux-source-4.6

Procure a versão mais atualizada em https://packages.debian.org/sid/armel/kernel/
Algumas correções importantes foram realizadas a partir da versão 4.6 no arquivo (link: https://sites.google.com/site/ubuntu4us/artigos/configuracao-de-hardware/network-attached-storage/patches-para-kirkwood-iomega_ix2_200-dts)
arch/arm/boot/dts/kirkwood-iomega_ix2_200.dts

mkdir ~/src; cd ~/src
tar xf /usr/src/linux-source-4.6.tar.xz
cd linux-source-4.6
unxz /usr/src/linux-config-4.6/config.armel_none_marvell.xz
cp -vi /usr/src/linux-config-4.6/config.armel_none_marvell .config
unxz /usr/src/linux-patch-4.6-rt.patch.xz
cp /usr/src/linux-patch-4.6-rt.patch ~/src/linux-source-4.6
patch -p1 --dry-run -i ../linux-patch-4.6-rt.patch
se não der erros: patch -p1 -i ../linux-patch-4.6-rt.patch
echo "-kirkwood-iomega-ix2-200" > localversion-rt

nano /etc/kernel-pkg.conf
# The maintainer information.
maintainer := Ademar Arvati Filho
email := vanaware@vanaware.com
# Priority of this version (or urgency, as dchanges would call it)
priority := Low
# This is the Debian revision number (defaulted to $(version)-10.00.Custom in debian/rules) 
 debian = $(version)


mkdir -p ~/src/overlay/examples/etc/kernel/postinst.d/


cp -arf /usr/share/kernel-package/* ~/src/overlay/

nano ~/src/overlay/post-install
#! /bin/bash
set -e
#${version} = 4.6.1-kirkwood-iomega-ix2-200-arvati1
#${IMAGE_TOP} = /root/src/linux-source-4.6/debian/linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati1
#examples/etc/kernel/postinst.d/ix2-200


#/root/src/linux-source-4.6/debian/linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati1/boot/System.map-4.6.1-kirkwood-iomega-ix2-200-arvati1
#/root/src/linux-source-4.6/debian/linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati1/boot/vmlinuz-4.6.1-kirkwood-iomega-ix2-200-arvati1
#/root/src/linux-source-4.6/debian/linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati1/boot/config-4.6.1-kirkwood-iomega-ix2-200-arvati1


if [ "$IMAGE_TOP" != "" ]; then
if [ "$version" != "" ]; then
#find ${IMAGE_TOP}/ -type f -print > /root/src/post-install-msg
mkdir -p "${IMAGE_TOP}/etc/kernel/postinst.d/$version/"
mkdir -p "${IMAGE_TOP}/etc/kernel/postrm.d/$version/"
mkdir -p "${IMAGE_TOP}/usr/lib/linux-image-${version}/"
cp "${IMAGE_TOP}/../examples/etc/kernel/postinst.d/ix2-200" "${IMAGE_TOP}/etc/kernel/postinst.d/$version/"
cp "${IMAGE_TOP}/../examples/etc/kernel/postrm.d/ix2-200" "${IMAGE_TOP}/etc/kernel/postrm.d/$version/"
cp "${IMAGE_TOP}/../../arch/arm/boot/dts/kirkwood-iomega_ix2_200.dtb" "${IMAGE_TOP}/usr/lib/linux-image-${version}/"
cp "${IMAGE_TOP}/../../arch/arm/boot/dts/kirkwood-iomega_ix2_200.dts" "${IMAGE_TOP}/usr/lib/linux-image-${version}/"

fi
fi


exit 0
chmod +x ~/src/overlay/post-install


nano ~/src/overlay/ChangeLog
=ST-source-=V (=D) unstable; urgency=low


* This is a dummy changelog for packages generated by kernel-package. At
some point, there shall be hooks for the user to substitute a
changelog entry, but currently this is just a stub.


-- Manoj Srivastava <srivasta@debian.org> Sat, 19 Aug 2006 16:37:36 -0500




Local variables:
mode: debian-changelog
End:


nano ~/src/overlay/examples/etc/kernel/postinst.d/ix2-200

#! /bin/bash
set -e
version="$1"
vmlinuz_location="$2"


# passing the kernel version is required
[ -z "$version" ] && exit 1


MODULEDIR=/lib/modules/$version
HEADERDIR=/usr/src/linux-headers-$version


boot='/boot'
if [ -n "$vmlinuz_location" ]; then
# Where is the image located?
boot=$(dirname "$vmlinuz_location")
fi
initramfs_location="$boot/initrd.img-$version"
bootarg="-b $boot"


# avoid running multiple times
if [ -n "$DEB_MAINT_PARAMS" ]; then
eval set -- "$DEB_MAINT_PARAMS"
if [ -z "$1" ] || [ "$1" != "configure" ]; then
exit 0
fi
fi

cat "$vmlinuz_location" "/usr/lib/linux-image-${version}/kirkwood-iomega_ix2_200.dtb" > "$boot/zImage+dtb-${version}"
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n Linux+dtb-${version} -d "$boot/zImage+dtb-${version}" "$boot/uImage+dtb-${version}"


if ! which update-initramfs >/dev/null ; then
exit 0
fi
# exit if kernel does not need an initramfs
if [ -n "$INITRD" ] && [ "$INITRD" = 'No' ]; then
exit 0
fi
# avoid running multiple times
if [ -n "$DEB_MAINT_PARAMS" ]; then
eval set -- "$DEB_MAINT_PARAMS"
if [ -z "$1" ] || [ "$1" != "configure" ]; then
exit 0
fi
fi
# we're good - create initramfs. update runs do_bootloader
if ! [ -e "$initramfs_location" ]; then
INITRAMFS_TOOLS_KERNEL_HOOK=1 update-initramfs -c -t -k "$version" $bootarg
fi
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs -d "$initramfs_location" "$boot/uInitrd-${version}"

chmod +x ~/src/overlay/examples/etc/kernel/postinst.d/ix2-200

nano ~/src/overlay/examples/etc/kernel/postrm.d/ix2-200
#! /bin/sh

set -e

if [ -n "$INITRD" ] && [ "$INITRD" = 'No' ]; then
    exit 0
fi
version="$1"
vmlinuz_location="$2"

# Note we only trigger on a remove, and not again on purge
if [ -n "$DEB_MAINT_PARAMS" ]; then
    eval set -- "$DEB_MAINT_PARAMS"
    case "$1" in
        remove)
            : echo nop
            ;;
        *)
            exit 0;
    esac
fi

# passing the kernel version is required
[ -z "$version" ] && exit 1

boot='/boot'
if [  -n "$vmlinuz_location" ]; then
    # Where is the image located? We'll place the initrd there.
    boot=$(dirname "$vmlinuz_location")
    bootarg="-b $boot"
fi

# try and remove the initramfs, and do not care if it fails
if which update-initramfs >/dev/null ; then
    update-initramfs -d -k "$version" $bootarg || true
fi
# try and remove files, and do not care if it fails
if [ -e "$boot/initrd.img-$version" ]; then
   rm -f "$boot/initrd.img-$version"  || true
fi
if [ -e "$boot/uInitrd-${version}" ]; then
   rm -f "$boot/uInitrd-${version}"  || true
fi
if [ -e "$boot/uImage+dtb-${version}" ]; then
   rm -f "$boot/uImage+dtb-${version}"  || true
fi
if [ -e "$boot/zImage+dtb-${version}" ]; then
   rm -f "$boot/zImage+dtb-${version}"  || true
fi
chmod +x ~/src/overlay/examples/etc/kernel/postrm.d/ix2-200

Adicione as dependencias abaixo para o pacote IMAGE:
nano ~/src/overlay/Control

 | u-boot-tools | mtd-utils


Baixe o arquivo config e salve em
~/src/overlay/config
~/src/linux-source-4.6/.config

Compilando o kernel


cd ~/src/linux-source-4.6
export TOOL_PREFIX="arm-linux-gnueabi" 
export CC="${TOOL_PREFIX}-gcc" 
export CXX="${TOOL_PREFIX}-g++"
export CROSS_COMPILE="${TOOL_PREFIX}-" 
export CFLAGS="-march=armv5te -mfloat-abi=soft -marm" 
export ARCH="arm"
export DEB_HOST_ARCH=armel
export LOCALVERSION="-arvati2" 
export CONCURRENCY_LEVEL=`grep -m1 cpu\ cores /proc/cpuinfo | cut -d : -f 2`
export INSTALL_MOD_PATH=/root/src/modules
export MODULE_LOC="${INSTALL_MOD_PATH}"
export UIMAGE_LOADADDR=0x8000
export KPKG_OVERLAY_DIR=/root/src/overlay
export DEBIAN_REVISION_MANDATORY=true
export INITRD=true


make menuconfig

make kernelrelease

make-kpkg clean 
make dtbs
make uImage
make modules
make modules_install

make-kpkg --rootcmd fakeroot --initrd --revision 1 kernel_image  > log_file 2>&1 & 
make-kpkg --rootcmd fakeroot --initrd --revision 1 kernel_headers  >> log_file 2>&1 & 
make-kpkg --rootcmd fakeroot --initrd --revision 1 kernel_source  >> log_file 2>&1 & 

ou simplesmente

make-kpkg --rootcmd fakeroot binary-arch kernel_source  > log_file 2>&1 & 

watch 'head -n 2 log_file; tail log_file'

conferir arquivos no pacote:
dpkg-deb -c ../linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati2_1_armel.deb | less

Instalando na Máquina alvo

copie os arquivos para o alvo:
scp  ../*.deb root@192.168.1.13:/root

instalar pacotes deb:
ssh root@192.168.1.13
sudo dpkg -i linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati2_1_armel.deb
sudo dpkg -i linux-headers-4.6.1-kirkwood-iomega-ix2-200-arvati2_1_armel.deb


Copiar backup para servidor tftp:

exit
exit
CTRL+A + q
sudo lxc-stop -n crossjessie

scp root@192.168.1.13:/boot/*-4.6.1-kirkwood-iomega-ix2-200-arvati2 /var/lib/tftpboot/
scp root@192.168.1.13:/usr/lib/linux-image-4.6.1-kirkwood-iomega-ix2-200-arvati2/* /var/lib/tftpboot/

Testar e Instalar na memória flash


Acesso ao IX200 pelo terminal serial


screen /dev/ttyUSB0 115200

Teste de Inicialização com o tFtp Server

Se quiser testar o boot com um tftp server:
setenv bootargs_console 'console=ttyS0,115200 mtdparts=orion_nand:0x100000@0x000000(uboot)ro,0x20000@0xA0000(env)ro,0x300000@0x100000(uImage),0x1C00000@0x400000(rootfsroot=/dev/mapper/root-root'
setenv bootargs $(bootargs_console)
setenv serverip 192.168.1.31
setenv ipaddr 192.168.1.13
tftpboot 0x01100000 uInitrd-4.6.1-kirkwood-iomega-ix2-200-arvati2
tftpboot 0x00800000 uImage+dtb-4.6.1-kirkwood-iomega-ix2-200-arvati2
bootm 0x00800000 0x01100000

Altere o root=/dev/mapper/root-root acima para o root adequado para sua instalação !!!

Antes copie os arquivos do kernel para o diretório do tftp server /var/lib/tftpboot especificado em cat /etc/default/tftpd-hpa

Inicializando pela Memória Flash

Primeiro verifique:
cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00100000 00004000 "uboot"
mtd1: 00020000 00004000 "env"
mtd2: 00300000 00004000 "uImage"
mtd3: 01c00000 00004000 "rootfs"

flash_eraseall /dev/mtd2
flash_eraseall /dev/mtd3

#TODO
nandwrite -p /dev/mtd2 /boot/uImage+dtb-4.6.1-kirkwood-iomega-ix2-200-arvati2
nandwrite -p /dev/mtd3 /boot/uInitrd-4.6.1-kirkwood-iomega-ix2-200-arvati2
reboot


Configurando a Inicialização pela Memória Flash (configurar apenas uma vez)

setenv mtdids 'nand0=orion_nand'
setenv mtdparts 'mtdparts=orion_nand:0x100000@0x000000(uboot)ro,0x20000@0xA0000(env),0x300000@0x100000(uImage),0x1C00000@0x400000(rootfs)'
setenv bootargs_console 'console=ttyS0,115200 mtdparts=orion_nand:0x100000@0x000000(uboot)ro,0x20000@0xA0000(env)ro,0x300000@0x100000(uImage),0x1C00000@0x400000(rootfs) root=/dev/mapper/root-root'
setenv bootcmd 'setenv bootargs $(bootargs_console); nand read 0x800000 uImage; nand read 0x1100000 rootfs; bootm 0x00800000 0x01100000'
saveenv
reset

Ajuste o valor de root corretamente !!! se preferir ajustar com o UUID faça assim =>        root=UUID=

O comando para continuar com o boot é:

run bootcmd

Encerrando a máquina virtual

exit
CTRL+a + q
sudo lxc-stop -n crossjessie --kill






Comments