Create new virtual machine and install Ubuntu from step 2 to it. VirtualBox may use a ISO-image as drive in virtual machine.If you plan to use Ubuntu with the GUI, you must dedicate at least 1.5Gb of RAM for the virtual machine. When you select a smaller size of RAM you may receive errors when you create the image of the firmware.使用虚拟机管理工具一台新的虚拟机以及步骤2下载好的光盘镜像。大多数的虚拟机环境都可以支持直接把 iso 文件作为光盘载入。如果你打算使用ubuntu的GUI界面，内存最好设置为1.5G以上。如果你给虚拟机的内存太小了，在编译固件的时候，可能会出错。

Start your virtual machine and open Terminal on it.装好Ubuntu 以后，运行，进入终端。

Install git:

用以下指令安装 git。
sudo apt-get update
sudo apt-get install git

Go to directory /opt and run command for create the local copy of repository:用以下步骤创建一个本地的源码副本：

cd /opt
sudo git clone https://bitbucket.org/padavan/rt-n56u.git

This copies all the source code, creates a local git-repository. Directory /opt/rt-n56u will be the root of the git-repository.

这步会把整个源码目录复制回来建立本地的副本，目录 /opt/rt-n56u会是这个代码的根目录。

Read the document /opt/rt-n56u/readme.eng.txt and install all the required packages that are listed in it:

To build the firmware, for example, for router RT-N65U uncomment (remove the simbol #) the line:
然后把你需要编译的路由型号取消注释（删除#号）

CONFIG_FIRMWARE_PRODUCT_ID="RT-N65U"

and comment the line:
以及注释掉原来的那行。

#CONFIG_FIRMWARE_PRODUCT_ID="RT-N56U"

Save the file after edit.
修改完成以后，记得保存文件。

Clear source tree (every time before a new build)
在准备开始之前，我们还有一点工作要处理：清理源码树（基本上每次重新编译前都需要处理）

sudo ./clear_tree

Build the firmware:
开始吧：

sudo ./build_firmware

Created custom firmware file will be in the directory ./path_to_your_dir/rt-n56u/trunk/images. If you want to save the firmware that you created earlier - copy it to another location, because the command clear_tree overwrites the directory images.
你订制好的固件会存放在 /opt/rt-n56u/trunk/images 这个目录中。如果你想保存之前编译过的固件，记得每次编译好之后要把它复制出来，否则 clean_tree指令会清空它。

When repository updated a local source tree must be updated with command:
当源码更新的时候，你需要在 rt-n56n的根目录中升级：

sudo git pull

If you made any changes to the local repository, when you upgrade tree some files could not be copied. In this case, you must give the command:
如果你修改过代码导致更新会出现冲突，这时候用以下的方式进行处理

sudo git stash
sudo git pull

If toolchain sources (cross-compiler and tools for building) is changed you must re-build it:
如果工具链的代码更新了，你需要重新编译一个工具链：