# NXP IMX6 嵌入式板子一些笔记

#### Set device a fix MAC address on Linux layer.

`vi /etc/init.d/networking`

on start handler.

```bash
start)
        echo -n "Configuring network interfaces... "
        sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
        #========set fix mac address by Carlos
        echo "[USER]/etc/init.d/networking: start to change the fix mac address for device."
        ifconfig eth0 down                           
        echo "[USER]/etc/init.d/networking: config the mac address to 5A:A1:6A:97:F3:C8."   
        ifconfig eth0 hw ether 5A:A1:6A:97:F3:C8
        echo "[USER]/etc/init.d/networking: link up."
        ifconfig eth0 up
        echo ""
        #========set by Carlos finish
        ifup -a
        echo "done."
        ;;
```

note: The original `README` has been changed to `README.old`

## Compiling the Linux Kernel for IMX6

`make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean`

`make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v7_defconfig`

`make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig` (optional)

`make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16`

* The compiled output `zImage` is saved on `arch/arm/boot`
* The compiled `.dtb` files are saved on the `arch/arm/boot/dts`

## Starting compiled dirty Linux Kernel

### config nfs on your host

#### installing nfs-kernel-server on your host

`sudo apt-get install nfs-kernel-server rpcbind`

#### config exports on your host

`sudo vim /etc/exports`

and you need to add the NFS sharing path on the exports: `/home/carlos/nfs *(rw,sync,no_root_squash)`

#### changing the version of nfs-kernel-server

Note, the nfs version of ubuntu 20.04 is too high to transform file for uboot. So we need to modify the version config manually by

`sudo vim /etc/default/nfs-kernel-server`

changing the version `RPCNFSDCOUNT="-V 2 8"`

#### restarting the nfs

`sudo /etc/init.d/nfs-kernel-server restart`

### copy the zImage to the nfs

`cp -r arch/arm/boot/zImage /home/carlos/nfs`

`cp -r arch/arm/boot/dts/imx6ull-14x14-evk.dtb /home/carlos/nfs`

### some operations on your device uboot console

Ensure that the uboot args is `console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw`

`dhcp`

`nfs 80800000 192.168.31.2:/home/carlos/nfs/zImage`

`nfs 83000000 192.168.31.2:/home/carlos/nfs/imx6ull-14x14-evk.dtb`

`bootz 80800000 - 83000000`

### replacing new kernel zImage on EMMC

* Transfer the zImage from host to device by `scp -r arch/arm/boot/zImage root@192.168.31.210:/run/media/mmcblk1p1/zImage`

## IMX6ULL快速使用笔记

### uboot

#### 代码

`git clone git@github.com:carloscn/imx-uboot.git`

### 编译

使用compile.sh编译

```C
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mx6ull_14x14_ddr512_emmc_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16
```

### 下载

#### 方法一：imdown.elf

使用imdown.elf工具下载到sd卡，在代码仓库中已经集成，`burn_tools`。方法就是插上SD卡，使用命令`sudo ./imxdown.elf u-boot.bin /dev/sdd` 后面的/dev/sdd使用 df -l来查看是不是自己的内存卡。

#### 方法二：uboot sd或emmc命令

uboot 支持 EMMC 和 SD 卡，因此也要提供 EMMC 和 SD 卡的操作命令。一般认为 EMMC和 SD 卡是同一个东西，所以没有特殊说明，本教程统一使用 MMC 来代指EMMC 和 SD 卡。uboot 中常用于操作 MMC 设备的命令为“mmc”。

如果当前uboot没有损坏，我们可以使用uboot来更新uboot。编译好的uboot放在nfs或者tftp文件夹里面。使用tftp把数据加载到ram中。

`tftp 80800000 u-boot.imx`

![](https://raw.githubusercontent.com/carloscn/images/main/typora20220924135514.png)

一共是384000字节，（384000/512 = 750个块 = 0x2ee个块）

再由ram加载到sd卡：

`mmc list` ：查看emmc列表 `mmc dev 0 0`：选中sd卡0的第0个分区 `mmc write 80800000 2 2ee` 从ram的80800000起始地址的写 0分区第2个块 长度 2ee

![](https://raw.githubusercontent.com/carloscn/images/main/typora20220924140030.png)

note:

* 如果是烧写mmc，还需要`mmc partconf 1 1 0 0 //分区配置，EMMC 需要这一步`
* 千万不要烧写SD卡或者EMMC的前两个块，里面保存着分区表。

### 配置uboot环境

EMMC 启动：`setenv bootargs console=ttymxc0,115200 root=/dev/mmcblk1p2 rootwait rw`

![](https://raw.githubusercontent.com/carloscn/images/main/typora20220924142937.png)

网络启动：`setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.137.18:/home/pjw/linux/nfs/rootfs,proto=tcp rw ip=192.168.137.20:192.168.137.18:192.168.1.1:255.255.255.0::eth0:off'`

![](https://raw.githubusercontent.com/carloscn/images/main/typora20220924143010.png)

### 在boot环境烧写zImage到emmc或sd卡

`fatinfo mmc 1:1` `fatls mmc 1:1` `fatload mmc 1:1 80800000 zImage` 把emmc里面的zimage加载到RAM `tftp 80800000 zImage` 把zImage数据加载到RAM `fatwrite mmc 1:1 80800000 zImage 0x5c2720` 把ram里面数据保存在emmc分区，命名为zimage 然后可以使用fatls查看。
