jueves, 1 de septiembre de 2016


*** Primero Preparamos el Entorno y las herramientas ***
*Estando ya como root
~#
~# apt-get -y install bc curl gcc git libncurses5-dev lzop make u-boot-tools
~# apt-get install libssl-dev
~# apt-get install gcc-arm-linux-gnueabi
*tambien podemos descargar el toolchain desde Launchpad y escoger la version 4.7:
https://launchpad.net/gcc-arm-embedded/+download
*En CROSS_COMPILE va la ruta donde se encuentra el compilador con todo y prefijo si es que no se instala.
~# export CROSS_COMPILE=arm-linux-gnueabi-
////////////////////////////////////////////////////////////////////////
*** U-Boot, the bootloader ***
*Obtenemos u-boot del sitio web oficial asi:
~# git clone git://git.denx.de/u-boot-imx.git u-boot
~# cd u-boot/
~/u-boot# export CROSS_COMPILE=arm-linux-gnueabi-
~/u-boot# export ARCH=arm
~/u-boot# make distclean
~/u-boot# make mx23_olinuxino_config
~/u-boot# make u-boot.sb
* Este binario no es booteable directamente en el imx233, entonces se convierte en un formato leible para el Soc con esta herramienta de U-Boot
~/u-boot# tools/mxsboot sd u-boot.sb u-boot.sd
~/u-boot# cd ..
///////////////////////////////////////////////////////////////////////////////////
*** Crear el kernel ***
*Obtenemos kernel linux del sitio web oficial asi:
~# git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux
~# cd linux
~/linux# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- mxs_defconfig
*Para cambiar algo en la configuracion del kernel hacemos(Deshabilitar si no se usa: Device Drivers->SPI support):
~/linux# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
~/linux# make LOADADDR=0x40008000 uImage modules
Image Name:   Linux-4.8.0-rc2
Created:      Wed Aug 24 15:37:08 2016
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    4137056 Bytes = 4040.09 kB = 3.95 MB
Load Address: 40008000
Entry Point:  40008000
  Kernel: arch/arm/boot/uImage is ready

~/linux# make imx23-olinuxino.dtb
  DTC     arch/arm/boot/dts/imx23-olinuxino.dtb
~/linux# cd ..
///////////////////////////////////////////////////////////////////////////////////
*** Crear un Sistema de Archivos(file system) Debian ***
~# apt-get install qemu
~# apt-get install qemu-user-static
~# apt-get install binfmt-support
~# apt-get install dpkg-cross
*Instalar multistrap asi:
~# apt-get install multistrap
~# mkdir system
~# cd system
*Luego crear un archivo de configuracion
~/system# nano config_multistrap
*Poner asi:

[General]
directory=target-rootfs
cleanup=true
noauth=true
unpack=true
debootstrap=Debian Net Utils
aptsources=Debian

[Debian]
packages=apt lsof
source=http://archive.debian.org/debian/
keyring=debian-archive-keyring
suite=wheezy
components=main contrib non-free

[Net]
#Basic packages to enable the networking
packages=netbase net-tools ethtool udev iproute iputils-ping ifupdown isc-dhcp-client ssh
source=http://archive.debian.org/debian/

[Utils]
#General purpose utilities
packages=locales adduser nano less wget dialog
source=http://archive.debian.org/debian/

*Luego:
~/system# mkdir rootfs
~/system# multistrap -a armel -d rootfs -f config_multistrap
*Esperar que salga asi sino es error:
Multistrap system installed successfully in /root/system/rootfs/.
~/system#
~/system# cp /usr/bin/qemu-arm-static rootfs/usr/bin/
~/system# mkdir rootfs/dev/pts
~/system# mount -t devpts devpts rootfs/dev/pts
~/system# mount -t proc proc rootfs/proc
~/system# mount -t sysfs sys rootfs/sys
**Necesario para error dpkg: error processing openssh-server (--configure):
~/system# mount -o bind /dev rootfs/dev 
~/system# chroot rootfs
*Aqui ya estamos en la maquina virtual arm,ejecutar:
# uname -a
Linux ezg 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:28 UTC 2016 armv7l GNU/Linux
# export LANG=en_US.UTF-8 LC_ALL=C LANGUAGE=en_US.UTF-8
# dpkg --configure -a
# dpkg-reconfigure locales ##solo para cambiar locales
# dpkg-reconfigure tzdata ##solo para cambiar la zona horaria
*Para ver los paquuetes
# dpkg --get-selections | more
# apt-get install apt-utils dialog locales ##por si acaso no se instalaron
# apt-get install dhcp3-client udev netbase ifupdown iproute openssh-server iputils-ping wget net-tools ntpdate nano less ##solo si no se instalaron
# apt-get install psmisc
*Para cambiar el password
# passwd
*Para principales configuraciones
# nano /etc/hostname
 imx233
# hostname imx233
# nano /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
# ping www.google.com  ##para probar conexion
# apt-get update
# nano /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
#eth0 MAC address , si se desea cambiar la mac
hwaddress ether 00:04:25:12:34:56

auto eth1
iface eth1 inet dhcp

auto eth2
iface eth2 inet dhcp

auto wlan0
iface wlan0 inet dhcp

wpa-ssid YourSSIDname
wpa-psk YourWPAkey

auto usb0
allow-hotplug usb0
iface usb0 inet dhcp

# nano /etc/ssh/sshd_config
PermitRootLogin yes  ##Para acceso root

*Para Set el debug port (donde ttyS0 es el puerto Habil):
# nano /etc/inittab
T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt102

*Para Set rules to change wlan dongles
# nano /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=='"net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"'

*Para la microSD partitions mounting
# nano /etc/fstab
/dev/mmcblk0p3   /           auto   errors=remount-ro   0   1
proc /proc proc defaults 0 0

*Para Adicionar los estandar repositorios copiar:
*Para squeeze:
#nano /etc/apt/sources.list
deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free
deb http://archive.debian.org/debian/  squeeze main contrib non-free
deb-src http://archive.debian.org/debian/  squeeze main contrib non-free

*Para Wheezy:
#nano /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
deb http://security.debian.org/ wheezy/updates main contrib non-free
deb-src http://security.debian.org/ wheezy/updates main contrib non-free

# apt-get update ##importante
# sync
# exit
~/system# umount rootfs/dev/pts rootfs/proc rootfs/dev rootfs/sys
~/system# rm rootfs/usr/bin/qemu-arm-static
~/system# cd ..
///////////////////////////////////////////////////////////////////////////////////////////////
****Para crear una Imagen del Sistema de Archivos para SD card
*Se crea y particiona
# mkdir build
# dd if=/dev/zero of=build/sdcard.img bs=1M count=1000
# (echo o; echo n; echo p; echo 1; echo ; echo +2M; echo t; echo 53; echo w;) | fdisk build/sdcard.img
# (echo n; echo p; echo 2; echo         ; echo +40M; echo t; echo 2 ; echo c; echo w; ) | fdisk build/sdcard.img
# (echo n; echo p; echo 3; echo         ; echo    ; echo w; ) | fdisk build/sdcard.img
# fdisk -l build/sdcard.img

*Se copia el u-boot
# dd if=u-boot/u-boot.sd of=build/sdcard.img seek=2048 conv=notrunc

*Se copia el kernel para esto crea un dispositivo loop
# mkdir ~/mnt
# fdisk -l build/sdcard.img | egrep '^\S+2' | awk '{ print $2*512}'
3145728 # => offset de la partition noyau
# losetup -o `fdisk -l build/sdcard.img | egrep '^\S+2' | awk '{ print $2*512}'` /dev/loop0 build/sdcard.img
# mkfs.vfat /dev/loop0
# mount -o loop /dev/loop0 ~/mnt
# cp linux/arch/arm/boot/uImage ~/mnt/
# cp linux/arch/arm/boot/dts/imx23-olinuxino.dtb ~/mnt/
# umount ~/mnt
# losetup -d /dev/loop0

*Se copia el rootfs (sistema de archivos)
# losetup -o `fdisk -l build/sdcard.img | egrep '^\S+3' | awk '{ print $2*512}'` /dev/loop0 build/sdcard.img
# mkfs.ext3 -L rootfs /dev/loop0
# mount -o loop /dev/loop0 ~/mnt
# cp -pdRv rootfs/* ~/mnt
* Se puede instalar los modulos del kernel(para que funcione depmod)
# cd ~/linux
~/linux# make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=~/mnt  modules_install
~/linux# cd ..
# umount ~/mnt
# losetup -d /dev/loop0

*Se copia a la Sd card suponiendo montada en /dev/sdc
dd if=sdcard.img |pv|dd of=/dev/sdc
/////////////////////////////////////////////////////////////////////////////////////
*** Adicionar partición SWAP para aumentar la memoria fisica. ****
*Utilizar parted o gparted y a la ultima particion reducirla unos 120MB sera suficiente,ahora esta sera la ultima particion.Guardar los cambios y colocar el sd al olinuxino.
*Luego Arrancar el sistema en el olinuxino, logearse como: root y passwd root
*Luego ver las particiones en /dev asi:
#ls /dev/mmcblk0*
/dev/mmcblk0  /dev/mmcblk0p1  /dev/mmcblk0p2  /dev/mmcblk0p3  /dev/mmcblk0p4

*luego mkswap -f -c [dispositivo]
mkswap -f -c /dev/mmcblk0p4
*swapon [dispositivo]
swapon /dev/mmcblk0p4
*luego ver con free
free
*Para hacerlo permanente
#nano /etc/fstab
*Adicionar
/dev/mmcblk0p4        swap    swap    defaults    0 0