Senin, 26 Agustus 2013

Xathrya Sabertooth

Xathrya Sabertooth


Linux Boot Process – BIOS

Posted: 25 Aug 2013 10:19 AM PDT

In order for a computer to successfully boot into device we know, a computer should pass some process which we refer as boot process. The BIOS, operating system, and harware components must all be working properly. Failure of any of these three elemens will likely result in a failed boot sequence.

BIOS is a abbreviation of Basic Input Output. It is a firmware, software written into special chip on motherboard.

Whenever a machine is powered on , the 1st program to run is BIOS. Primary jobs of BIOS are:

  • POST : Performs the Power On Self Test, or POST , to test the peripherals if they are functioning properly at hardware level.
  • CPU Initialization : BIOS checks the clock speed of CPU and will put the CPU on realmode. At the time of power on , cpu will be in real mode. In real mode cpu works on direct physical addresses only.
  • Memory Probing : BIOS checks for machine's available primary memory(RAM).
  • Basic Devices Initialization : BIOS initializes only those devices which are required to carry out the boot process. For example boot process requires basic I/O devices . So BIOS initializes standard input device and standard output device. Apart from basic I/O it also initializessome controllers like PCI controller, IDE controller. IDE controller are needed because without IDE controllers floppy disks / hard disks cant be read or written.
  • Creating Memory Map – BIOS creates real mode memory map or real mode address space. This memory map is always architecture specific. It expects the kernel image to be loaded directly at those addresses. That is why we build the kernel image ( bzImage ) according to the machine's architecture. The bzImage carries real mode , architecture specific addresses so that it can find those direct addresses and can be loaded there.
  • Loading MBR – The last job of BIOS is to find the boot device and to jump to its sector '0' ( boot sector ). BIOS has got access to only sector '0′ of a boot device. Whatever BIOS finds in sector '0' , it loads that in real mode address space.

The BIOS job has finished and the control goes to whatever code written on the disk boot sector.

Linux Kernel Configuration

Posted: 25 Aug 2013 10:07 AM PDT

Having Linux kernel source code allow us to open possibility to customize / configure the kernel as you wish. Main kernel image is built as a static image, and some part of linux kernel image is also built as loadable modules (device driver). The image is always resident in memory while some services are added to the kernel at runtime in the form of modules. Complete kernel image constitute static kernel image plus run-time loadable modules. Linux kernel configuration allows you to decide , which feature you want to include in linux kernel image , which feature you do not want to include or which service you want to make as a loadable kernel module etc.

This article will try to cover all important ones for configuring Linux kernel.

Text Based Configuration

1. Interactive Configuration

Kernel has provide an interactive text based kernel configuration utility using Makefile. If you use ‘make config’, it will configure itself. In fact, it is useful for quite experienced kernel developers and not for the beginners. The result of this command is shown below:

# make config    scripts/kconfig/conf arch/x86/Kconfig    *  * Linux Kernel Configuration  *  *  * General setup  *  Prompt for development and/or incomplete code/drivers (EXPERIMENTAL) [N/y/?] y    Local version – append to kernel release (LOCALVERSION) [] y    Automatically append version information to the version string (LOCALVERSION_AUTO) [N/y/?] y    Kernel compression mode    > 1. Gzip (KERNEL_GZIP)      2. Bzip2 (KERNEL_BZIP2)      3. LZMA (KERNEL_LZMA)      4. LZO (KERNEL_LZO)    choice[1-4?]: 1    Support for paging of anonymous memory (swap) (SWAP) [N/y/?] y    System V IPC (SYSVIPC) [N/y/?] y    BSD Process Accounting (BSD_PROCESS_ACCT) [N/y/?] y      BSD Process Accounting version 3 file format (BSD_PROCESS_ACCT_V3) [N/y/?] (NEW) y    *    * RCU Subsystem    *    RCU Implementation    > 1. Tree-based hierarchical RCU (TREE_RCU)      2. UP-only small-memory-footprint RCU (TINY_RCU)    choice[1-2]: 1    Enable tracing for RCU (RCU_TRACE) [N/y/?] y    Tree-based hierarchical RCU fanout value (RCU_FANOUT) [32]

This command starts an interactive kernel configuration script. Once invoked, it will continuously prompts for user input at every step . User can enter any one of the four options:

  1. Yes – For building the particular feature with kernel’s static image.
  2. No – For not including the feature at all in the kernel image
  3. Module – For build this feature as loadable kernel module.
  4. ? – For help, gives brief description on the feature.

Script prompts for each and every option and expects the input for each of the options. There are so many options available so it is very tedious and time consuming way. Now you can guess the reason why it not a preferred way to configure linux kernel.

2. Predefined Configuration Target

Tell the Makefile to use predefined configuration target. There are some predefined configuration, which are: defconfig, oldconfig, randconfig, allmodconfig, allyesconfig, allnoconfig.

2.1 defconfig

Use default configuration to configure kernel.

make defconfig

It’s easy and you would not expecting much other than default parts.

This utility generates default configuration for linux kernel. This default configuration is based on the configuration options preferred and used by linux kernel maintainers on their own machines. Once the task done, you can view and modify the configuration as you wish.

2.2 oldconfig

Technically speaking, it updates the current kernel configuration by using the current .config file and prompting for any new options that have been added to the kernel.

make oldconfig

If you think your old configuration is fit to your condition, you can always use this. Like defconfig, you can view and modify the configuration once the configuration finished.

There is also a variant to this, silentoldconfig, which prints nothing to screen except a question.

2.3 randconfig

Generates a new kernel configuration with random answers to all of the different option.

make randconfig

2.4 allmodconfig

Generates a new kernel configuration in which modules are enabled whenever possible.

make allmodconfig

2.6 allyesconfig

Generates a new kernel configuration with all options set to yes.

make allyesconfig

2.7 allnoconfig

enerates a new kernel configuration with all options set to no.

make allnoconfig

Console Based Configuration

The very popular way of configuring kernel. Still using command line interface, but it’s at least graphically on terminal (using ncurses).

make menuconfig

It will opens a graphical console in which all kernel configuration options are arranged into categories. These categories are further categorized into subcategories. Just browse through and keep on selecting options until you reach the specific configuration option you need to modify.

This method is easier than the methods we have covered so far.

If you think you have it enough, you can select < Exit > to exit the configuration. You can also exit without doing any modification. A configuration, .config file, will be created / updated.

GUI Based Configuration

1. X11 Based Configuration

Using help of X window system.

make xconfig

Make xconfig is X11-based graphical configuration utility. It arranges all the configuration options into left and right pane. You can easily browse through and select different options easily.

2. GTK Based Configuration

Using GTK+ based system. Make sure you have GTK libraries installed.

make gconfig

Other

Other method to configure kernel. It doesn’t use Makefile like other methods we have discussed, but instead we directly modify the configuration file. Configuration is saved as a file “.config” without quote.

The configuration file is located in the root of the kernel source tree. It consists of some lines, usually in the format VARIABLE=value

The variable are the kernel options where the value can be y, n and other value defined for that options.

Installing RetroPie on Raspberry Pi

Posted: 25 Aug 2013 08:33 AM PDT

Raspberry Pi, a small computer powered by ARM architecture is a very interesting board for learning embedded system. From Media center into a simple server, Raspberry Pi has opened wide possibility to be explored. Who knows, Pi now can also be used as “Game Console“? What we talk here is Raspberry Pi now can be used as a Game Emulator to play many game console platform.

For this article I use following:

  1. Slackware64 14.0
  2. Windows 8
  3. Raspberry Pi model B
  4. RetroPie image

You can use either Linux (in this article, Slackware) or Windows (in this article Windows 8). Just pick one and follow the rest of article for your choice.

Obtain the Materials

The Operating System images I used is RetroPie, which can be downloaded from RetroPie site. This is huge image, around 1.3GB for it. When extracted, it occupy around 2GB storage space.

The RetroPie software is basically EmulationStation and a stripped down version of Raspbian.

Prepare the Disk (SD Card)

To boot the Raspberry Pi, an installation media and storage media is needed. All we need is a single SD card. The bigger space, the better. You need space for OS and additional space to hold your ROMS. On this article I use my 8GB SD card. You can use any SD card you want, but I recommend to use at least 4GB SD card. The image we download on previous section will be stored on this card and later installed. Make sure you have a way to write on SD card.

Windows-based Instruction

For Windows user, you can follow this section to “burn” the image. For this purpose you need additional software for writing to SD card, such as Win32DiskImager utility.

  1. Extract the image (in this case pidora-18-r1c.zip) so you will get an .img file.
  2. Insert SD card into SD card reader and check what drive letter it assigned to. For example G:\
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Run the Win32DiskImager with administrator privileges.
  5. Select the image we have extracted.
  6. Select the drive letter of the SD card on our machine. Make sure you have the correct drive, or you will destroy data on that drive.
  7. Click Write and wait. The process should be not long.
  8. Exit the imager and eject the SD card

Beside Win32DiskImager, you can also use other tool such as Flashnul.

  1. Follow step 1 to step 3 for Win32DiskImager’s solution
  2. Extract Flashnul from the archive
  3. Open command prompt with elevated privilege (administrator privilege).
  4. Go to your extracted directory and run flashnul with argument “-p”. For example: flashnul -p
  5. You will get list of physical drive attached on your machine, and list of drive. Make sure the drive is correct. At time of writing this article, the SD card is detected as device number 1 with and mounted to drive G:
  6. Load the image to flashnul: flashnul 1 -L pidora-18-r1c.img
  7. If you get an access denied error, try re-plugging the SD card and make sure to close all explorer windows or folders open for the device. If still get denial, try substitute the device number with its drive letter: flashnul G: -L pidora-18-r1c.img

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Linux-based Instruction

Writing image on Linux is easier, in my opinion. The utility we use is “dd” which is already bundled on most distro. Make sure you know the correct device file for your SD card. In my machine I use a built in card reader and detect my SD card as /dev/sdb. It might be different on your system so better check it. For this article I use /dev/sdb to refer to SD card.

  1. Extract the image (in this case pidora-18-r1c.zip) so you will get an .img file.
  2. Insert SD card into SD card reader .
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Unmount the SD card if it is mounted. We need the whole SD card so if you see partition such as /dev/sdb1, etc its better you unmount them all.
  5. Write the image to SD card. Make sure you replace the input file after if= argument with correct path to .img file and “/dev/sdb” in the output file of= argument with your device. Also make sure to use whole SD drive and not their partition (i.e. not use /dev/sdb1, /dev/sdb1, etc). The command: dd bs=4M if=pidora-18-r1c.img of=/dev/sdb
  6. Run sync as root. This will ensure the write cache is flushed and safe to unmount SD card.
  7. Remove SD card from card reader.

If you hesitate to use terminal and prefer to use GUI method, here is the tutorial. Note that we

  1. Do step 1 to step 3 for previous tutorial. Make sure your directory or image file doesn’t contain any spaces.
  2. Install the ImageWriter tool from https://launchpad.net/usb-imagewriter
  3. Launch the ImageWriter tool (needs administrative privileges)
  4. Select the image file (in this case pidora-18-r1c.img) to be written to the SD card (note: because you started ImageWriter as administrator the starting point when selecting the image file is the administrator’s home folder so you need to change to your own home folder to select the image file)
  5. Select the target device to write the image to. In my case, it’s /dev/sdb
  6. Click the “Write to device” button
  7. Wait for the process to finish and then insert the SD card in the Raspberry Pi

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Booting Up and Configuring

RetroPie differs from other distribution I have written so far. The connection for audio and video are same to other, the difference comes to the configuration it has.

You will be asked to configure your controller. This isn’t the calibration that is needed to control the various games that you will be playing, this is to configure your retro controller, joystick or even keyboard to navigate the EmulationStation software.

Once you are done, tap the button or key you set as Menu, and select Exit. This will quit out of EmulationStation and go back to the command line. From there, it’s like other OSes, you should enter GUI manually using

startx

The GUI will be launched, enabling us to make necessary changes to controller configuration. In the file manager, open RetroPie\Configs\all and runretroarch.cfg in the text editor. Things might different for each controller available in the market, adjust with your needs.

Running the Pi

To resize the SD card after installation, you can follow this article.

To log in on your Raspberry pi you can use the default login, which is:

Username: root
Password: raspberrypi

Have fun :D

Installing Pidora on Raspberry Pi

Posted: 25 Aug 2013 05:08 AM PDT

Raspberry Pi, a small computer powered by ARM architecture is a very interesting board for learning embedded system. In this article we will discuss about how to install how to install Pidora on Raspberry Pi.

For this article I use following:

  1. Slackware64 14.0
  2. Windows 8
  3. Raspberry Pi model B
  4. Pidora version 18

You can use either Linux (in this article, Slackware) or Windows (in this article Windows 8). Just pick one and follow the rest of article for your choice.

Obtain the Materials

The Operating System images I used is Pidora which use hard-float system ABI provided by Raspberry Pi on their download page. The version I use is latest version at time of writing this article (per August 24th, 2013) and only use hard-float ABI. You can either direct download on this link, or download by torrent by this link.

Prepare the Disk (SD Card)

To boot the Raspberry Pi, an installation media and storage media is needed. All we need is a single SD card. On this article I use my 8GB SD card. You can use any SD card you want, but I recommend to use at least 4GB SD card. The image we download on previous section will be stored on this card and later installed. Make sure you have a way to write on SD card.

Windows-based Instruction

For Windows user, you can follow this section to “burn” the image. For this purpose you need additional software for writing to SD card, such as Win32DiskImager utility.

  1. Extract the image (in this case pidora-18-r1c.zip) so you will get an .img file.
  2. Insert SD card into SD card reader and check what drive letter it assigned to. For example G:\
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Run the Win32DiskImager with administrator privileges.
  5. Select the image we have extracted.
  6. Select the drive letter of the SD card on our machine. Make sure you have the correct drive, or you will destroy data on that drive.
  7. Click Write and wait. The process should be not long.
  8. Exit the imager and eject the SD card

Beside Win32DiskImager, you can also use other tool such as Flashnul.

  1. Follow step 1 to step 3 for Win32DiskImager’s solution
  2. Extract Flashnul from the archive
  3. Open command prompt with elevated privilege (administrator privilege).
  4. Go to your extracted directory and run flashnul with argument “-p”. For example: flashnul -p
  5. You will get list of physical drive attached on your machine, and list of drive. Make sure the drive is correct. At time of writing this article, the SD card is detected as device number 1 with and mounted to drive G:
  6. Load the image to flashnul: flashnul 1 -L pidora-18-r1c.img
  7. If you get an access denied error, try re-plugging the SD card and make sure to close all explorer windows or folders open for the device. If still get denial, try substitute the device number with its drive letter: flashnul G: -L pidora-18-r1c.img

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Linux-based Instruction

Writing image on Linux is easier, in my opinion. The utility we use is “dd” which is already bundled on most distro. Make sure you know the correct device file for your SD card. In my machine I use a built in card reader and detect my SD card as /dev/sdb. It might be different on your system so better check it. For this article I use /dev/sdb to refer to SD card.

  1. Extract the image (in this case pidora-18-r1c.zip) so you will get an .img file.
  2. Insert SD card into SD card reader .
  3. If it is not new, format it. Or at least make sure there is only one partition (FAT32 is recommended).
  4. Unmount the SD card if it is mounted. We need the whole SD card so if you see partition such as /dev/sdb1, etc its better you unmount them all.
  5. Write the image to SD card. Make sure you replace the input file after if= argument with correct path to .img file and “/dev/sdb” in the output file of= argument with your device. Also make sure to use whole SD drive and not their partition (i.e. not use /dev/sdb1, /dev/sdb1, etc). The command: dd bs=4M if=pidora-18-r1c.img of=/dev/sdb
  6. Run sync as root. This will ensure the write cache is flushed and safe to unmount SD card.
  7. Remove SD card from card reader.

If you hesitate to use terminal and prefer to use GUI method, here is the tutorial. Note that we

  1. Do step 1 to step 3 for previous tutorial. Make sure your directory or image file doesn’t contain any spaces.
  2. Install the ImageWriter tool from https://launchpad.net/usb-imagewriter
  3. Launch the ImageWriter tool (needs administrative privileges)
  4. Select the image file (in this case pidora-18-r1c.img) to be written to the SD card (note: because you started ImageWriter as administrator the starting point when selecting the image file is the administrator’s home folder so you need to change to your own home folder to select the image file)
  5. Select the target device to write the image to. In my case, it’s /dev/sdb
  6. Click the “Write to device” button
  7. Wait for the process to finish and then insert the SD card in the Raspberry Pi

At this point, you have successfully written image to your SD card. And I assume you are. You can proceed to next stage.

Running the Pi

You have write image and at this point your raspberry pi is ready. Now set up raspberry pi to boot: insert your SD card back to raspberry pi, put on power, plug video output (either HDMI or RCA).

To resize the SD card after installation, you can follow this article.

To log in on your Raspberry pi you can use the default login, which is:

Username: root
Password: raspberrypi

Have fun :D

Raspberry Pi GPIO Reference

Posted: 25 Aug 2013 05:03 AM PDT

This is reference to Raspberry Pi GPIO.

GPIO or General Purpose Input/Output is a generic pin on a chip whose behavior (including whether it is an input or output pin) can be controlled (programmed) through software. One pin can be act as either Input or Output but can’t be both at a time, means it cannot send and receive data at same time.

GPIO pins have no special purpose defined, and go unused by default.

The Raspberry Pi allows peripherals and expansion boards (such as Rpi Gertboard) to access the CPU by exposing the inputs and outputs.

Quick Cheatsheet

raspberry-pi-gpio-cheat-sheet

Only covers P1 Header

Hardware

P1 Header

Raspberry Pi (both model A and B) has 26 pin 2.54mm (100 mil) expansion header, marked as P1, arranged in a 2×13 strip. They provide 8 GPIO pins plus access to I²C, SPI, UART, as well as +3.3 V, +5 V and GND supply lines. Pin one is the pin in the first column and on the bottom row.

RPi_P1_header

The GPIO pin-header layout, seen from top. Three pins changed between PCB rev.1 and rev.2.

GPIOs

GPIO voltage levels are 3.3 V and are not 5V tolerant. There is no over voltage protection on the board. Thus, you should use an external board with buffers, level conversion, and analog I/O rather than soldering directly onto the main board.

All the GPIO pins can be reconfigured to provide alternate functions, SPI, PWM, I²C, and so. At reset only pins GPIO 14 & 15 are assigned to the alternate function UART, those two can be switched back to GPIO to provide a total of 17 GPIO pins.

Each GPIO can interrup, high/low/rise/fall/change. There is currently no support for GPIO interrupts in the official kernel. However there is a patch, requiring compilation of modified source tree.

GPIO input hysteresis (Schmitt trigger) can be on or off, output slew rate can be fast or limited, and source and sink current is configurable from 2mA up to 16mA. The chipset GPIO pins 0-27 are in the same block and these properties are set per block, not per pin.

R-Pi PCB Revision 2 UPDATE: The R-Pi Rev.2 board being rolled out starting in September 2012 adds 4 more GPIO on a new connector called P5, and changes some of the existing P1 GPIO pinouts. On Rev2, GPIO_GEN2 [BCM2835/GPIO27] is routed to P1 pin 13, and changes what was SCL0/SDA0 to SCL1/SDA1: SCL1 [BCM2835/GPIO3] is routed to P1 pin 5, SDA1 [BCM2835/GPIO2] is routed to P1 pin 3. Also the power and ground connections previously marked “Do Not Connect” on P1 will remain as connected, specifically: P1-04:+5V0, P1-09:GND, P1-14:GND, P1-17:+3V3, P1-20:GND, P1-25:GND.

P1 Header Pin, top row:

Pin Number Pin Name Rev1 Pin Name Rev2 Hardware Notes Alt 0 Function Other Alternative Functions
P1-02 5V0 Supply through input poly fuse
P1-04 5V0 Supply through input poly fuse
P1-06 GND
P1-08 GPIO 14 Boot to Alt 0 -> UART0_TXD ALT5 = UART1_TXD
P1-10 GPIO 15 Boot to Alt 0 -> UART0_RXD ALT5 = UART1_RXD
P1-12 GPIO 18 PCM_CLK ALT4 = SPI1_CE0_N ALT5 = PWM0
P1-14 GND
P1-16 GPIO23 ALT3 = SD1_CMD ALT4 = ARM_RTCK
P1-18 GPIO24 ALT3 = SD1_DAT0 ALT4 = ARM_TDO
P1-20 GND
P1-22 GPIO25 ALT3 = SD1_DAT1 ALT4 = ARM_TCK
P1-24 GPIO08 SPI0_CE0_N
P1-26 GPIO07 SPI0_CE1_N

P1 header Pin, bottom row:

Pin Number Pin Name Rev1 Pin Name Rev2 Hardware Notes Alt 0 Function Other Alternative Functions
P1-01 3.3 V 50 mA max (01 & 17)
P1-03 GPIO 0 GPIO 2 1K8 pull up resistor I2C0_SDA / I2C1_SDA
P1-05 GPIO 1 GPIO 3 1K8 pull up resistor I2C0_SCL / I2C1_SCL
P1-07 GPIO 4 GPCLK0 ALT5 = ARM_TDI
P1-09 GND
P1-11 GPIO17 ALT3 = UART0_RTS ALT4 = SPI1_CE1_N ALT5 = UART1_RTS
P1-13 GPIO21 GPIO27 PCM_DOUT / reserved ALT4 = SPI1_SCLK ALT5 = GPCLK1 / ALT3 = SD1_DAT3 ALT4 = ARM_TMS
P1-15 GPIO22 ALT3 = SD1_CLK ALT4 = ARM_TRST
P1-17 3.3 V 50 mA max (01 & 17)
P1-19 GPIO10 SPI0_MOSI
P1-21 GPIO9 SPI0_MISO
P1-23 GPIO11 SPI0_SCLK
P1-25 GND

Legend:

Colour legend
+5 V
+3.3 V
Ground, 0V
UART
GPIO
SPI
I²C

Pin 3 (SDA0) and Pin 5 (SCL0) are preset to be used as an I²C interface. So there are 1.8 kilohm pulls up resistors on the board for these pins.

Pin 12 supports PWM .

It is also possible to reconfigure GPIO connector pins P1-7, 15, 16, 18, 22 (chipset GPIOs 4 and 22 to 25) to provide an ARM JTAG interface. However ARM_TMS isn’t available on the GPIO connector (chipset pin 12 or 27 is needed). Chipset pin 27 is available on S5, the CSI camera interface however.

It is also possible to reconfigure GPIO connector pins P1-12 and 13 (chipset GPIO 18 and 21) to provide an I2S (a hardware modification may be required) or PCM interface. However, PCM_FS and PCM_DIN (chipset pins 19 and 20) are needed for I2S or PCM.

A second I²C interface (GPIO02_ALT0 is SDA1 and GPIO03_ALT0 is SCL1) and two further GPIOs (GPIO05_ALT0 is GPCLK1, and GPIO27) are available on S5, the CSI camera interface.

Power pins

The maximum permitted current draw from the 3.3V pins is 50mA.

Maximum permitted current draw from the 5V pin is the USB Input current (usually 1A) minus any current draw from the rest of the board.

  1. Model A: 1000mA – 500mA -> max current draw: 500mA
  2. Model B: 1000mA – 700mA -> max current draw: 300mA

Be very careful with the 5 V pins P1-02 and P1-04. If you short 5 V to any other P1 pin you may permanently damage your RasPi. Before probing P1, it’s a good idea to strip short pieces of insulation off a wire and push them over the 5 V pins so you don’t accidentally short them with a probe.

GPIO Hardware Hacking

The complete list of chipset GPIO pins are available on the GPIO connector is:

0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25

(On the Revision2.0 Raspberry Pis, this list changes to 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 22, 23, 24, 25, 27, with 28, 29, 30, 31 additionally available on the P5 header).

P1-03 and P1-05 (SDA0 and SCL0 / SDA1 and SCL1) have 1.8 kiloohm pull-up resistors to 3.3V.

If 17 GPIOs aren’t sufficient for your project, there are a few other signals potentially available, with varying levels of software and hardware (soldering iron) hackery skills:

GPIO02, 03, 05 and 27 are available on S5 (the CSI interface) when a camera peripheral is not connected to that socket, and are configured by default to provide the functions SDA1, SCL1, CAM_CLK and CAM_GPIO respectively. SDA1 and SCL1 have 1K6 pull-up resistors to 3.3 V.

GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function.

There are a few other chipset GPIO pins accessible on the PCB but are in use:

  • GPIO16 drives status LED D5 (usually SD card access indicator)
  • GPIO28-31 are used by the board ID and are connected to resistors R3 to R10 (only on Rev1.0 boards).
  • GPIO40 and 45 are used by analogue audio and support PWM. They connect to the analogue audio circuitry via R21 and R27 respectively.
  • GPIO46 is HDMI hotplug detect (goes to pin 6 of IC1).
  • GPIO47 to 53 are used by the SD card interface. In particular, GPIO47 is SD card detect (this would seem to be a good candidate for re-use). GPIO47 is connected to the SD card interface card detect switch; GPIO48 to 53 are connected to the SD card interface via resistors R45 to R50.

Raspberry Pi BCM2835 Datasheet

Based on BCM2835 datasheet, including any relevant errata, with a couple of extra columns.

Any GPIOs that aren’t connected on the RaspberryPi Model B revision 1.0 circuit board are crossed out, and the GPIOs available on the GPIO Connector (P1) are in bold, with their default function (according to the schematics) in bold italics.

GPIO Pins Alternative Function Assignment

Pull ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 RPi Rev1.0 signal name RPi Rev2.0 signal name RPi Rev1.0 connection RPi Rev2.0 connection
GPIO0
High SDA0 SA5 <reserved> SDA0 SDA0 P1-03 S5-14
GPIO1
High SCL0 SA4 <reserved> SCL0 SCL0 P1-05 S5-13
GPIO2
High SDA1 SA3 <reserved> SDA1 SDA1 S5-14 P1-03
GPIO3
High SCL1 SA2 <reserved> SCL1 SCL1 S5-13 P1-05
GPIO4
High GPCLK0 SA1 <reserved> ARM_TDI GPIO_GCLK GPIO_GCLK P1-07 P1-07
GPIO5
High GPCLK1 SA0 <reserved> ARM_TDO CAM_CLK CAM_CLK S5-12 S5-12
GPIO6
High GPCLK2 SOE_N / SE <reserved> ARM_RTCK LAN_RUN LAN_RUN IC3-12 IC3-12
GPIO7
High SPI0_CE1_N SWE_N / SRW_N <reserved> SPI_CE1_N SPI_CE1_N P1-26 P1-26
GPIO8
High SPI0_CE0_N SD0 <reserved> SPI_CE0_N SPI_CE0_N P1-24 P1-24
GPIO9
Low SPI0_MISO SD1 <reserved> SPI_MISO SPI_MISO P1-21 P1-21
GPIO10
Low SPI0_MOSI SD2 <reserved> SPI_MOSI SPI_MOSI P1-19 P1-19
GPIO11
Low SPI0_SCLK SD3 <reserved> SPI_SCLK SPI_SCLK P1-23 P1-23
GPIO12
Low PWM0 SD4 <reserved> ARM_TMS nc nc
GPIO13
Low PWM1 SD5 <reserved> ARM_TCK nc nc
GPIO14
Low TXD0 SD6 <reserved> TXD1 TXD0 TXD0 P1-08 P1-08
GPIO15
Low RXD0 SD7 <reserved> RXD1 RXD0 RXD0 P1-10 P1-10
GPIO16
Low <reserved> SD8 <reserved> CTS0 SPI1_CE2_N CTS1 STATUS_LED_N STATUS_LED_N D5 (OK LED) D5 (ACT LED)
GPIO17
Low <reserved> SD9 <reserved> RTS0 SPI1_CE1_N RTS1 GPIO_GEN0 GPIO_GEN0 P1-11 P1-11
GPIO18
Low PCM_CLK SD10 <reserved> BSCSL SDA / MOSI SPI1_CE0_N PWM0 GPIO_GEN1 GPIO_GEN1 P1-12 P1-12
GPIO19
Low PCM_FS SD11 <reserved> BSCSL SCL / SCLK SPI1_MISO PWM1 nc nc
GPIO20
Low PCM_DIN SD12 <reserved> BSCSL / MISO SPI1_MOSI GPCLK0 nc nc
GPIO21
Low PCM_DOUT SD13 <reserved> BSCSL / CE_N SPI1_SCLK GPCLK1 GPIO_GEN2 CAM_GPIO P1-13 S5-11
GPIO22
Low <reserved> SD14 <reserved> SD1_CLK ARM_TRST GPIO_GEN3 GPIO_GEN3 P1-15 P1-15
GPIO23
Low <reserved> SD15 <reserved> SD1_CMD ARM_RTCK GPIO_GEN4 GPIO_GEN4 P1-16 P1-16
GPIO24
Low <reserved> SD16 <reserved> SD1_DAT0 ARM_TDO GPIO_GEN5 GPIO_GEN5 P1-18 P1-18
GPIO25
Low <reserved> SD17 <reserved> SD1_DAT1 ARM_TCK GPIO_GEN6 GPIO_GEN6 P1-22 P1-22
GPIO26
Low <reserved> <reserved> <reserved> SD1_DAT2 ARM_TDI nc nc
GPIO27
Low <reserved> <reserved> <reserved> SD1_DAT3 ARM_TMS CAM_GPIO GPIO_GEN2 S5-11 P1-13
GPIO28
- SDA0 SA5 PCM_CLK <reserved> CONFIG0 GPIO_GEN7 R10 / R8 P5-3
GPIO29
- SCL0 SA4 PCM_FS <reserved> CONFIG1 GPIO_GEN8 R9 / R7 P5-4
GPIO30
Low <reserved> SA3 PCM_DIN CTS0 CTS1 CONFIG2 GPIO_GEN9 R6 / R4 P5-5
GPIO31
Low <reserved> SA2 PCM_DOUT RTS0 RTS1 CONFIG3 GPIO_GEN10 R5 / R3 P5-6
GPIO32
Low GPCLK0 SA1 <reserved> TXD0 TXD1 nc nc
GPIO33
Low <reserved> SA0 <reserved> RXD0 RXD1 nc nc
GPIO34
High GPCLK0 SOE_N / SE <reserved> <reserved> nc nc
GPIO35
High SPI0_CE1_N SWE_N / SRW_N <reserved> nc nc
GPIO36
High SPI0_CE0_N SD0 TXD0 <reserved> nc nc
GPIO37
Low SPI0_MISO SD1 RXD0 <reserved> nc nc
GPIO38
Low SPI0_MOSI SD2 RTS0 <reserved> nc nc
GPIO39
Low SPI0_SCLK SD3 CTS0 <reserved> nc nc
GPIO40
Low PWM0 SD4 <reserved> SPI2_MISO TXD1 PWM0_OUT PWM0_OUT R21 R21
GPIO41
Low PWM1 SD5 <reserved> <reserved> SPI2_MOSI RXD1 nc nc
GPIO42
Low GPCLK1 SD6 <reserved> <reserved> SPI2_SCLK RTS1 nc nc
GPIO43
Low GPCLK2 SD7 <reserved> <reserved> SPI2_CE0_N CTS1 nc nc
GPIO44
- GPCLK1 SDA0 SDA1 <reserved> SPI2_CE1_N nc nc
GPIO45
- PWM1 SCL0 SCL1 <reserved> SPI2_CE2_N PWM1_OUT PWM1_OUT R27 R27
GPIO46
High <internal> HDMI_HPD_P HDMI_HPD_P IC1-6 IC1-6
GPIO47
High <internal> SD_CARD_DET SD_CARD_DET S8-10 S8-10
GPIO48
High <internal> SD_CLK_R SD_CLK_R R48 R48
GPIO49
High <internal> SD_CMD_R SD_CMD_R R47 R47
GPIO50
High <internal> SD_DATA0_R SD_DATA0_R R49 R49
GPIO51
High <internal> SD_DATA1_R SD_DATA1_R R50 R50
GPIO52
High <internal> SD_DATA2_R SD_DATA2_R R45 R45
GPIO53
High <internal> SD_DATA3_R SD_DATA3_R R46 R46
Pull ALT0 ALT1 ALT2 ALT3 ALT4 ALT5 RPi Rev1.0 signal name RPi Rev2.0 signal name RPi Rev1.0 connection RPi Rev2.0 connection

As in the table above, the GPIOs available on the GPIO Connector (P1) are in bold, with their default function (according to the schematics) in bold italics.

Special function legend:

Name Function Datasheet section GPIOs
SDA0
BSC master 0 data line BSC GPIO0 GPIO28 GPIO44
SCL0
BSC master 0 clock line BSC GPIO1 GPIO29 GPIO45
SDA1
BSC master 1 data line BSC GPIO2 GPIO44
SCL1
BSC master 1 clock line BSC GPIO3 GPIO45
GPCLK0
General purpose Clock 0 <TBD> GPIO4 GPIO20 GPIO32 GPIO34
GPCLK1
General purpose Clock 1 <TBD> GPIO5 GPIO21 GPIO42 GPIO44
GPCLK2
General purpose Clock 2 <TBD> GPIO6 GPIO43
SPI0_CE1_N
SPI0 Chip select 1 SPI GPIO7 GPIO35
SPI0_CE0_N
SPI0 Chip select 0 SPI GPIO8 GPIO36
SPI0_MISO
SPI0 MISO SPI GPIO9 GPIO37
SPI0_MOSI
SPI0 MOSI SPI GPIO10 GPIO38
SPI0_SCLK
SPI0 Serial clock SPI GPIO11 GPIO39
PWMx
Pulse Width Modulator 0..1 Pulse Width Modulator PWM0: GPIO12 GPIO18 GPIO40
PWM1: GPIO13 GPIO19 GPIO41 GPIO45
TXD0
UART 0 Transmit Data UART GPIO14 GPIO32 GPIO36
RXD0
UART 0 Receive Data UART GPIO15 GPIO33 GPIO37
CTS0
UART 0 Clear To Send UART GPIO16 GPIO30 GPIO39
RTS0
UART 0 Request To Send UART GPIO17 GPIO31 GPIO38
PCM_CLK
PCM clock PCM Audio GPIO18 GPIO28
PCM_FS
PCM Frame Sync PCM Audio GPIO19 GPIO29
PCM_DIN
PCM Data in PCM Audio GPIO20 GPIO30
PCM_DOUT
PCM data out PCM Audio GPIO21 GPIO31
SAx
Secondary mem Address bus Secondary Memory Interface many
SOE_N / SE
Secondary mem. Controls Secondary Memory Interface GPIO6 GPIO34
SWE_N / SRW_N
Secondary mem. Controls Secondary Memory Interface GPIO7 GPIO35
SDx
Secondary mem. data bus Secondary Memory Interface many
BSCSL SDA / MOSI
BSC slave Data, SPI slave MOSI BSC/SPI slave GPIO18
BSCSL SCL / SCLK
BSC slave Clock, SPI slave clock BSC/SPI slave GPIO19
BSCSL – / MISO
BSC <not used>, SPI MISO BSC/SPI slave GPIO20
BSCSL – / CE_N
BSC <not used>, SPI CSn BSC/SPI slave GPIO21
SPI1_CEx_N
SPI1 Chip select 0-2 Auxiliary I/O SPI1_CE0_N: GPIO18
SPI1_CE1_N: GPIO17
SPI1_CE2_N: GPIO16
SPI1_MISO
SPI1 MISO Auxiliary I/O GPIO19
SPI1_MOSI
SPI1 MOSI Auxiliary I/O GPIO20
SPI1_SCLK
SPI1 Serial clock Auxiliary I/O GPIO21
TXD1
UART 1 Transmit Data Auxiliary I/O GPIO14 GPIO32 GPIO40
RXD1
UART 1 Receive Data Auxiliary I/O GPIO15 GPIO33 GPIO41
CTS1
UART 1 Clear To Send Auxiliary I/O GPIO16 GPIO30 GPIO43
RTS1
UART 1 Request To Send Auxiliary I/O GPIO17 GPIO31 GPIO42
SPI2_CEx_N
SPI2 Chip select 0-2 Auxiliary I/O SPI2_CE0_N: GPIO43
SPI2_CE1_N: GPIO44
SPI2_CE2_N: GPIO45
SPI2_MISO
SPI2 MISO Auxiliary I/O GPIO40
SPI2_MOSI
SPI2 MOSI Auxiliary I/O GPIO41
SPI2_SCLK
SPI2 Serial clock Auxiliary I/O GPIO42
ARM_TRST
ARM JTAG reset <TBD> GPIO22
ARM_RTCK
ARM JTAG return clock <TBD> GPIO6 GPIO23
ARM_TDO
ARM JTAG Data out <TBD> GPIO4 GPIO24
ARM_TCK
ARM JTAG Clock <TBD> GPIO13 GPIO25
ARM_TDI
ARM JTAG Data in <TBD> GPIO4 GPIO26
ARM_TMS
ARM JTAG Mode select <TBD> GPIO12 GPIO27
Name Function Datasheet section GPIOs

P2 Header

P2 header is the VideoCore JTAG and use only during the production of the board. It cannot be used as the ARM JTAG. This connector is unpopulated in Rev 2.0 boards.

RPi_P2_header

Usefule P2 pins:

  1. Pin 1 – 3.3V (same as P1-01, 50mA max current draw across both of them)
  2. Pin 7 – GND
  3. Pin 8 – GND

P3 Header

P3 header, inpopulated, is the LAN9512 JTAG. This header is located directly next to P2 header.

RPi_P3_header

Usefule P3 pins:

  1. Pin 7 – GND

P5 Header

Added with the release of the Revision 2.0 PCB design. This pins located directly next to P1 header.

RPi_P5_header

(Seen from the back of the board).

P5 header pin out, top row:

Pin Number Pin Name Rev2 Hardware Notes Alt 0 Function Other Alternative Functions
P5-01 5V0 Supply through input poly fuse
P5-03 GPIO28 I2C0_SDA ALT2 = PCM_CLK
P5-05 GPIO30 ALT2 = PCM_DIN ALT3 = UART0_CTS ALT5 = UART1_CTS
P5-07 GND

P5 header pin out, bottom row:

Pin Number Pin Name Rev2 Hardware Notes Alt 0 Function Other Alternative Functions
P5-02 3.3 V 50 mA max (combined with P1)
P5-04 GPIO29 I2C0_SCL ALT2 = PCM_FS
P5-06 GPIO31 ALT2 = PCM_DOUT ALT3 = UART0_RTS ALT5 = UART1_RTS
P5-08 GND

Note that the connector is intended to be mounted on the bottom of the PCB, so that for those who put the connector on the top side, the pin numbers are swapped. Pin 1 and pin 2 are swapped, etc.

P6 Header

P6 header was added with the release of the Revision 2.0 PCB design. This header is located next to HDMI output.

RPi_P6_header

P6 pinout:

Pin Number Pin Name Rev2 Hardware Notes
P6-01 RUN Short to ground to reset the BCM2835
P6-02 GND

A reset button can be attached to the P6 header, with which the Pi can be reset. Momentarily shorting the two pins of P6 together will cause a soft reset of the CPU (which can also ‘wake’ the Pi from halt/shutdown state).

Internal Pull-Ups and Pull-Downs

The GPIO ports include the ability to enable and disable internal pull-up or pull-down resistors (see below for code examples/support of this).

Pull-up is Min. 50K Ohm, Max 65 KOhm.

Pull-down is Min. 50K Ohm, Max 60 KOhm.

Software

The foundation (Raspberry Pi Foundation) will not include a GPIO driver in the initial release. However the standard Linux GPIO drivers should work with minimal modification.

The community implemented SPI and I²C drivers, which will be integrated with the new Linux pinctrl.

Further reference

  1. http://en.wikipedia.org/wiki/GPIO

Installing OpenELEC on Raspberry Pi

Posted: 25 Aug 2013 04:43 AM PDT

Raspberry Pi, a small computer powered by ARM architecture is a very interesting board for learning embedded system. In this article we will discuss about how to install how to install OpenELEC on Raspberry Pi.

For this article I use following:

  1. Slackware64 14.0
  2. Windows 8
  3. Raspberry Pi model B
  4. OpenELEC

You can use either Linux (in this article, Slackware) or Windows (in this article Windows 8). Just pick one and follow the rest of article for your choice.

The installation process will be divide the content into three section according to the host platform:

  1. Automated Installation using Linux
  2. Installation on Linux
  3. Generic Installation for QEMU

What is OpenELEC?

OpenELEC is an embedded operating system built around XBMC, the open source entertainment media hub. Home Theatre PCs are known to be hard to install and configure and can take a massive amount of time to keep running. OpenELEC, on the other hand, is designed to be as lightweight as possible in terms of size and complexity meaning your HTPC becomes no harder to configure than satellite box or DVD player. With it’s small footprint, OpenELEC is also ideal for small systems based on Atom or Fusion platforms so we won’t need a whole computer in your living room!

OpenELEC is designed to be lightweight. It support many system such as NVIDIA’s ION platform, AMD’s Fusion platform, and Broadcom’s Crystal HD chip. OpenELEC can support high definition content on machines with low-powered processors by offloading video content to supported graphics cards and decoders. This means we can build (or buy) small, silent machines to be effectively used as a media center.

Obtain the Materials

The Operating System images I used is latest version of OpenELEC. The version I use is latest version, at time of writing this article (per August 25th, 2013), and can be download from their official site here. Verify your package, you should have a tarball package (file that ends in .tar.bz2) with correct checksum.

Exploring the Package

Extract the content and you will have a folder with some content on it.

For the latest package we download (version 3.1.6) there will be three directory four plaintext, one shell script file, and one image file.

The three directories are:

3rdparty
Like implied by name, the 3rdparty code and file. There is only one folder there, bootloader. The files inside there are used to make a bootloader for OpenELEC’s SD Card.
licenses
Various license used. Including license by third party such as NVIDIA, etc.
target
Our primary interest. There are four files here: KERNEL, KERNEL.md5, SYSTEM, and SYSTEM.md5. Actually there are two important file there, KERNEL and SYSTEM. The files with .md5 extension are used for checksum. KERNEL file is used as OpenELEC kernel (Linux kernel ARM boot executable zImage little endian) and the SYSTEM file is the root filesystem (technically a Squashfs filesystem, little endian).

The shell script (name: create_sdcard) is used to create SD Card. If you read the script, you will see that the script will create two partition. One partition is using FAT32 and the other uses ext2. The FAT32 partition (first partition) is set to 16 cylinders or approximately 130MB. This is interesting information.

Prepare the Disk (SD Card)

To boot the Raspberry Pi, an installation media and storage media is needed. All we need is a single SD card. On this article I use my 8GB SD card. You can use any SD card you want, but I recommend to use at least 4GB SD card. The image we download on previous section will be stored on this card and later installed. Make sure you have a way to write on SD card.

Installation

(1) Automated Installation on Linux

Insert SD Card your Linux system. Look for what device it is recognized as. It can be /dev/sdX, /dev/mmcblk0, etc.

Invoke following command with root privilege:

./create_sdcard /dev/sdX # /dev/sdX is your device

It is very important to make sure you have the right device as it will be wiped as part of the process.

(2) Installation on Windows

There is no batch script or vbscript (or similar to that) for Windows so we should do manually.

Formatting the SD Card

OpenELEC needs properly formatted SD Card. It requires two partition with one of theme is formatted with an ext4 filesystem. A third party such as the MiniTool® Partition Wizard can be used for this purpose. The Home Edition is free for home use only.

After inserting the SD card and starting Partition Wizard, you will get something like this:

pw-shot1

Delete all existing partition and create two partitions. Both are primary partition. The first partition is parted as FAT32 with capacity of 130MB. Give the rest SD Card storage to EXT2 (or other EXT) partition. Name the first as Boot and the later as System.

Last but important part, create bootloader configuration. Create a file ‘cmdline.txt’ on the SD card with following content:

boot=/dev/mmcblk0p1 disk=/dev/mmcblk0p2 quiet

Copying OpenELEC to SD Card.

Now mount the first partition (the FAT32 one) to your Windows. Copy the target/KERNEL as kernel.img to partition. Also copy the target/SYSTEM. Next, copy the content of 3rdparty\bootloader folder also to that partition. Also copy openelec.ico and README.md. At this point you should have following items on your partition:

  1. LICENSE.broadcom
  2. README
  3. SYSTEM
  4. bootcode.bin
  5. cmdline.txt
  6. config.txt
  7. fixup.dat
  8. kernel.img
  9. openelec.ico
  10. start.elf

Running the Pi

You have write image and at this point your raspberry pi is ready. Now set up raspberry pi to boot: insert your SD card back to raspberry pi, put on power, plug video output (either HDMI or RCA).

To resize the SD card after installation, you can follow this article.

Finally, you can login to Raspberry Pi using

Username root
Password openelec

If you do not have a USP Input device, you can enable XBMC wifi remote access (via Android/iOS etc) by editing config files directly.

Happy hacking :D

Formatting QEMU Disk Image with Specific Filesystem

Posted: 25 Aug 2013 03:19 AM PDT

Testing and debugging an operating system require an environment. Many people prefer to use emulator and virtualization software like QEMU, VMware, or VirtualBox for this job.

If you have read my previous article about mounting QEMU Hard Disk Image, you should note that the partition should already have been formatted with a specific filesystem. This is bad if we just create a fresh QEMU disk image.

This article will discuss about how to format the partition inside QEMU disk image. The assumption made here is the disk image is fresh and no more operation than partitioning it. I assume you have at least one partition (such as FAT32, Linux, etc. Any!).

In this article I use:

  1. Slackware64 14.0 as host system
  2. QEMU 1.4.0

I also provide a small empty raw image for play around (see next section).

Obtain the Materials

You can download an empty disk image here

The compressed image size is 2MB and the extracted (the image itself) is 2GB.

The disk image has two partition (as seen on fdisk):

  1. W95 FAT32, start from 2048 , end on 268287. This will be formatted as FAT32.
  2. Linux, start from 268288, end on 4194303. This will be formatted as EXT4.

There is nothing special about this image. The process I did is common and you can achieve it by yourself:

  1. Create empty qemu image file
    qemu-img create -f raw xath-testsuite-ext3.img 2G

    The image is in raw format. This is important as it is the simple one.
  2. Create the partition using fdisk.

We also need a Linux ISO image. We will use Slackware mini install which can be obtained here. In the rest of this article, we will refer this as minislack.iso.

Process

What we will do are:

  1. Format the hard disk / QEMU disk image using Linux installer.
  2. Interrupt the Linux installer, stop QEMU, mount the QEMU image on Linux and clean it up.

Formatting

Boot the disk with QEMU and Slackware as first boot

qemu-system-i386 xath-testsuite-ext3.img -cdrom minislack.iso -boot d

Once booted, just press enter. Press enter again when you are asked for keyboard layout. You will be brought to a terminal. Login as root with no password.

Our disk image is recognized as /dev/sda. To format a partition as FAT32 use mkfs.vfat and to format it as EXT4 use mkfs.ext4.

We will try the second one and I will leave you with the first one for you to play with ;)

mkfs.ext4 /dev/sda2

Finishing

Now for final touch. Still using the Slackware on QEMU, mount the /dev/sda1 and /dev/sda2. Your goal now is to remove the content. After this point, we can finally say “done!”.

Congratulation!

Tidak ada komentar:

Posting Komentar