Skip to content

Commit

Permalink
Added more work in smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
hak8or committed Apr 5, 2018
1 parent 5197350 commit 1b65d32
Show file tree
Hide file tree
Showing 17 changed files with 1,461 additions and 31 deletions.
2 changes: 1 addition & 1 deletion AT91SAM9N12/buildroot.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ For the ```Toolchain --->``` tab, select both ```Enable C++ support``` and ```En

Next up is the device tree we made [earlier](devicetree.md). Create a file called ```at91sam9n12ek_custom.dts``` in the Linux kernel source folder (in my case being ```output/build/linux-4.15.7/arch/arm/boot/dts/```) containing that device tree. In the Kernel tab, enable ```Build a Device Tree Blob```, select ```Use a device tree present in the kernel``` and for the file name put ```at91sam9n12ek_custom``` (yes, there is no file extension included even though it says file name). This will have the kernel build process create a file in the ```output/images``` folder for the compiled device tree with the ```.dtb``` file extension instead of us having to do this manually.

Lastly, we only have 4 MB for everything so compression is extremely important. For the root file system we do not need it to be writable, so we can use [SquashFS](https://www.tldp.org/HOWTO/SquashFS-HOWTO/whatis.html). This file system was designed specifically for space constrained systems and has tons of awesome features but has one large issue, it's read only. Also, the [xz](https://tukaani.org/xz/format.html) compression format seems to do the best on my system in terms of compression ratio. To enable the root file system to use squashfs with xz, go to ```Filesystem images --->``` and select ```squashfs root filesystem``` with ```Compression algorithm (xz)```. For the kernel, go to ```Kernel --->``` and ensure the ```Kernel binary format``` is a ```zImage``` with the compression set to ```zx compression```.
Lastly, we only have 4 MB for everything so compression is extremely important. For the root file system we do not need it to be writable, so we can use [SquashFS](https://elinux.org/Squash_FS_Howto). This file system was designed specifically for space constrained systems and has tons of awesome features but has one large issue, it's read only. Also, the [xz](https://tukaani.org/xz/format.html) compression format seems to do the best on my system in terms of compression ratio. To enable the root file system to use squashfs with xz, go to ```Filesystem images --->``` and select ```squashfs root filesystem``` with ```Compression algorithm (xz)```. For the kernel, go to ```Kernel --->``` and ensure the ```Kernel binary format``` is a ```zImage``` with the compression set to ```zx compression```.

To summarize, here is what you need to change:

Expand Down
Binary file added AT91SAM9N12/images/Linux_ath9k_search.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions AT91SAM9N12/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@ This board has:
* 4 MB of Dataflash (AT45DB321E-SHF-B)
* USB OTG and USB Device broken out (both only up to 12 Mbps Full Speed)

Originally this project was done years ago relying on Atmel forked branches of U-Boot and the Linux kernel from Atmel. While this did work, it meant having to use old non mainlined versions of each project. Later this project was restarted with the intention of using mainline sources for everything and BuildRoot to streamline the linux and root filesystem generation. The old version of this documentation, dubbed "Old School", can be found [here](OldSchool.md), and shows how to do everything **manually**. This includes compiling the linux kernel by hand to generate a zImage, creating a minimal root file system, and even using flash drive for the root file system including a native GCC toolchain!
Originally this project was done years ago relying on Atmel forked branches of U-Boot and the Linux kernel from Atmel. While this did work, it meant having to use old non mainlined versions of each project. Later this project was restarted with the intention of using mainline sources for everything and BuildRoot to streamline the linux and root filesystem generation. The old version of this documentation, dubbed "Old School", can be found [here](OldSchool.md), and shows how to do everything **manually**. This includes compiling the Linux kernel by hand to generate a zImage, creating a minimal root file system, and even using flash drive for the root file system including a native GCC toolchain!

This documentation will show the process of bringing a board like this up from start to finish, including describing the intended boot flow, how to configure all the software (AT91 Bootstrap, Kernel, root file system, BuildRoot, etc), show various bugs and issues found in the process (USB OTG was a fun one), how much space various functionality uses, and how to build a semi useful root file system (networking, Tmux, stress, htop, etc).
This documentation will show the process of bringing a board like this up from start to finish, including describing the intended boot flow, how to configure all the software (AT91 Bootstrap, Kernel, root file system, BuildRoot, etc), show various bugs and issues found in the process (USB OTG was a fun one), how much space various functionality uses, and how to build a semi useful root file system (networking, stress, htop, tmux, etc).

The end goal is to have a system that can do the following:

- Boot to a shell and be able to communicate with it over serial
- Networking support
- Use the [RNX-N150HG](https://wikidevi.com/wiki/Rosewill_RNX-N150HG) USB Wifi dongle to talk to the outside world
- Read only file system with compression (SquashFS)
- Run various tools (htop, stress, tmux, ping)
- If possible, an ssh server and [TCC](https://www.wikiwand.com/en/Tiny_C_Compiler) to compile a small C based demo program

## Status

Everything seems to work except NAND flash, likely due to soldering issues with the SAM9N12 BGA based package. Because NAND flash isn't working, it was decided to try and stick everything in the 32 Megabit Dataflash (yep, only 4 Megabytes for a bootloader, kerenel, and root filesystem). USB OTG is used for a Wifi dongle so we get networking support to make this more interesting.
Everything seems to work except NAND flash, likely due to soldering issues with the SAM9N12 BGA based package. Because NAND flash isn't working, it was decided to try and stick everything in the 32 Megabit Data flash (yep, only 4 Megabytes for a boot loader, kernel, and root file system). USB OTG is used for a Wifi dongle so we get networking support to make this more interesting.

## Boot Flow

The AT91SAM9N12 has a bootloader in ROM which can boot from NAND Flash, SPI Flash, SPI Dataflash, and can even boot directly into the linux kernel (therefore not needing U-Boot). There has been some reverse engineering work done on the bootloader [here](http://hobbygenius.co.uk/blog/1622).
The AT91SAM9N12 has a boot loader in ROM which can boot from NAND Flash, SPI Flash, SPI Data flash, and can even boot directly into the Linux kernel (therefore not needing U-Boot). There has been some reverse engineering work done on the boot loader [here](http://hobbygenius.co.uk/blog/1622).

The memory setup we will be using is as follows:

Expand All @@ -38,11 +47,11 @@ The memory setup we will be using is as follows:

As a rough overview to show in the grand scheme of things how this will look:

1. The bootloader will first look for any boot-able data in SPI Flash, SPI Dataflash, and NAND Flash. In our case, we have the AT91 BootStrap in Dataflash at an offset of zero (start of Dataflash).
2. The [AT91 Bootstrap](http://www.at91.com/linux4sam/bin/view/Linux4SAM/AT91Bootstrap) will initialize DRAM and then copy data from Dataflash (in our case the Kernel at an offset of ```0x7300```) into DRAM (at ```0x2200_0000```), and the Device Tree from Dataflash at an offset of ```0x4B00``` to DRAM at ```0x2100_0000```.
3. Then the bootloader will initialize the environment for the Linux kernel (address of device tree in a register, etc) and pass execution to the kernel.
1. The boot loader will first look for any boot-able data in SPI Flash, SPI Data flash, and NAND Flash. In our case, we have the AT91 BootStrap in Dataflash at an offset of zero (start of Data flash).
2. The [AT91 Bootstrap](http://www.at91.com/linux4sam/bin/view/Linux4SAM/AT91Bootstrap) will initialize DRAM and then copy data from Data flash (in our case the Kernel at an offset of ```0x7300```) into DRAM (at ```0x2200_0000```), and the Device Tree from Dataflash at an offset of ```0x4B00``` to DRAM at ```0x2100_0000```.
3. Then the boot loader will initialize the environment for the Linux kernel (address of device tree in a register, etc) and pass execution to the kernel.
4. Since the kernel is a zImage (self extracting kernel image), the kernel will uncompress itself, execute itself, read the device tree which was copied to RAM earlier, initialize various drivers based on the device tree entries, and lastly pass execution to whatever is relevant in the root file system.

## First boot

First things first, let's get the board powered up with the Dataflash erased. Upon bootup the bootloader in ROM of the SAM9N12 will configure basic clocking and the ```DBGU``` serial port on pins ```R5``` and ```R6``` to run at 115200 baud and output the text ```RomBOOT```. If you see this then it means a lot went right, such as power integrity, clocking, BGA packages soldered correctly, and of course no magic smoke means no shorts. [Next](SAMBA.md) we will look into getting setting up SAMBA so we can flash the AT91 Bootstrap to dataflash.
First things first, let's get the board powered up with the Dataflash erased. Upon bootup the boot loader in ROM of the SAM9N12 will configure basic clocking and the ```DBGU``` serial port on pins ```R5``` and ```R6``` to run at 115200 baud and output the text ```RomBOOT```. If you see this then it means a lot went right, such as power integrity, clocking, BGA packages soldered correctly, and of course no magic smoke means no shorts. [Next](SAMBA.md) we will look into getting setting up SAMBA so we can flash the AT91 Bootstrap to data flash.
Loading

0 comments on commit 1b65d32

Please sign in to comment.