Archives For June 2012

Yes, the last step. It doesn’t mean that I’m abandoning this project. Not at all. It just that it has reached the state I wanted it to reach from the very beginning: fairly stable, flexible u-boot distribution suitable to be used as an environment for OS bring-up. So now it’s time to get back to the original idea: get FreeBSD running on Raspberry Pi.

So, current state of affairs is raspberry-pi-uboot-20120621.tar.gz. It includes:

  • USB support
  • SD card support (FAT filesystem)
  • Support for built-in USB ethernet
  • Autoimport environment from uEnv.txt
  • Autorun of boot script (boot.scr)

Known problems:

  • two usb start in row without power cycle does not work
  • USB transaction errors when USB device is plugged into R-Pi
  • bootm command is not properly tested

Of course there is place for improvements and there will be some bugfixes for this branch. I’ll prepare USB driver (and, probably, SDHC) for upstream but it will be background activity and my primary objective for nearest future will be FreeBSD on R-Pi.

Initial support for SD card has just been pushed to github repo.

U-Boot 2012.04.01-00479-gb58d9ae-dirty (Jun 20 2012 - 11:47:13)

DRAM:  128 MiB
WARNING: Caches not enabled
MMC:   CAPS: 00000000
bcm2835_sdh: 0
Using default environment

In:    serial
Out:   serial
Err:   serial
Net:   Net Initialization Skipped
No ethernet found.
U-Boot> mmcinfo
Device: bcm2835_sdh
Manufacturer ID: 1b
OEM: 534d
Name: 00000
Tran Speed: 25000000
Rd Block Len: 512
SD version 2.0
High Capacity: No
Capacity: 1.9 GiB
Bus Width: 4-bit
U-Boot> fatls mmc 0
    16528   bootcode.bin
      127   cmdline.txt
   314691   loader.bin
  2047848   start.elf
   181196   kernel.img

5 file(s), 0 dir(s)

U-Boot>

More progress on the subject:

  • I cleaned up sources and pushed new version to github.
  • Stephen Warren submitted patches for R-Pi support to U-Boot mailing list here and here. His version is much cleaner so I spent some time combining his patches with ported USB driver. So now target is called rpi_b and you should use “make rpi_b_config” instead of “make raspberry_pi_config” step when building U-Boot from sources.
  • Pre-built binaries are available for download here.

And finally it works!

U-Boot 2012.04.01-00306-gecc6e3d-dirty (Jun 15 2012 - 19:05:09)

DRAM:  128 MiB
WARNING: Caches not enabled
Using default environment

In:    serial
Out:   serial
Err:   serial
Net:   No ethernet found.
Raspberry-Pi # usb start
(Re)start USB...
USB:   Core Release: 2.80a
scanning bus for devices... 3 USB Device(s) found
       scanning bus for ethernet devices... 1 Ethernet Device(s) found
Raspberry-Pi # dhcp
Waiting for Ethernet connection... done.
BOOTP broadcast 1
*** Unhandled DHCP Option in OFFER/ACK: 28
*** Unhandled DHCP Option in OFFER/ACK: 28
DHCP client bound to address 192.168.10.21
Using sms0 device
TFTP from server 192.168.10.1; our IP address is 192.168.10.21
Filename 'kernel.RPI'.
Load address: 0x700000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         ######################################################
done
Bytes transferred = 4597674 (4627aa hex)
Raspberry-Pi # ping 192.168.10.1
Waiting for Ethernet connection... done.
Using sms0 device
host 192.168.10.1 is alive
Raspberry-Pi #

OK. No visual progress, but short SitRep: I got control transfers working more stable and got bulk transfer somewhat working: U-Boot sends one packet and receives response, then all bulk transfers end up in STALL state. Investigating.


BOOTP broadcast 1
** smsc95xx_send(), len 342, buf 0x7e8db5e
BULK -> <3,2>
dev = 3 pipe = 2 buf = 07e8db5e size = 350 dir_out = 1
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 350, num_packets = 6, max = 64, buffer = 07e8db5e(07e8f490)
Tx: len = 350, actual = 350, err = 0
** smsc95xx_recv()
BULK -> <3,1>
dev = 3 pipe = 1 buf = 07fec698 size = 2048 dir_out = 0
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 2048, num_packets = 32, max = 64, buffer = 07fec698(07e8f490)
Rx: len = 2048, actual = 368, err = 0
packet received
packet received
Receive from protocol 0x800
Got IP
len=346, v=45
DHCPHandler: got packet: (src=67, dst=68, len=318) state: 3
Filtering pkt = 0
DHCPHandler: got DHCP packet: (src=67, dst=68, len=318) state: 3
DHCP: state=SELECTING bp_file: "kernel.RPI"
TRANSITIONING TO REQUESTING STATE
*** Unhandled DHCP Option in OFFER/ACK: 130
*** Unhandled DHCP Option in OFFER/ACK: 28
DhcpSendRequestPkt: Sending DHCPREQUEST
Transmitting DHCPREQUEST packet: len = 342
** smsc95xx_send(), len 342, buf 0x7e8dace
BULK -> <3,2>
dev = 3 pipe = 2 buf = 07e8dace size = 350 dir_out = 1
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 350, num_packets = 6, max = 64, buffer = 07e8dace(07e8f490)
Channel halted
Tx: len = 350, actual = 0, err = 0
BOOTP broadcast 2
** smsc95xx_send(), len 342, buf 0x7e8db5e
BULK -> <3,2>

dev = 3 pipe = 2 buf = 07e8dace size = 350 dir_out = 1
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 350, num_packets = 6, max = 64, buffer = 07e8dace(07e8f490)
Channel halted
Tx: len = 350, actual = 0, err = 0
BOOTP broadcast 2
** smsc95xx_send(), len 342, buf 0x7e8db5e
BULK -> <3,2>
dev = 3 pipe = 2 buf = 07e8db5e size = 350 dir_out = 1
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 350, num_packets = 6, max = 64, buffer = 07e8db5e(07e8f490)
Channel halted
Tx: len = 350, actual = 0, err = 0
** smsc95xx_recv()
BULK -> <3,1>
dev = 3 pipe = 1 buf = 07fec698 size = 2048 dir_out = 0
max_hc_xfer_size = 65535, max_hc_pkt_count = 511
xfer_len = 2048, num_packets = 32, max = 64, buffer = 07fec698(07e8f490)
HANG at line 533: 00000423

After rather busy weekend I finally got control transaction support for DWC OTG controller working on Raspberry Pi. U-Boot DWC OTG driver is cut-down version of Linux driver that works in polling mode. Stability is not very good at the moment though. And make sure to use latest firmware files. It does matter.

Next step – bulk transactions.

Repo: https://github.com/gonzoua/u-boot-pi

Raspberry-Pi # usb info
1: Hub,  USB Revision 1.10
 - DWC OTG RootHub
 - Class: Hub
 - PacketSize: 8  Configurations: 1
 - Vendor: 0x0000  Product 0x0000 Version 0.0
   Configuration: 1
   - Interfaces: 1 Self Powered 0mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 1
     - Class Hub
     - Endpoint 1 In Interrupt MaxPacket 8 Interval 255ms

2: Hub,  USB Revision 2.0
 - Class: Hub
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x0424  Product 0x9512 Version 2.0
   Configuration: 1
   - Interfaces: 1 Self Powered Remote Wakeup 2mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 1
     - Class Hub
     - Endpoint 1 In Interrupt MaxPacket 1 Interval 255ms

3: Vendor specific,  USB Revision 2.0
 - Class: Vendor specific
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x0424  Product 0xec00 Version 2.0
   Configuration: 1
   - Interfaces: 1 Self Powered Remote Wakeup 2mA
     Interface: 0
     - Alternate Setting 0, Endpoints: 3
     - Class Vendor specific
     - Endpoint 1 In Bulk MaxPacket 64
     - Endpoint 2 Out Bulk MaxPacket 64
     - Endpoint 3 In Interrupt MaxPacket 16 Interval 1ms

R-Pi Boot process

June 4, 2012 — 3 Comments

Just a note to myself to keep useful info.
Bakul Shah in freebsd-arm quotes R-Pi forum, but I failed to find original.

1. Stage 1 boot is in the on-chip ROM. Loads stage2 in the L2 cache!
2. Stage 2 is bootcode.bin. Enables SDRAM and loads stage3
3. Stage 3 is loader.bin. Knows about elf format and load start.elf
4. start.elf loads kernel.img (+ it is the main gpu code).
It reads config.txt, cmdline.txt and bcm2835.dtb
If the dtb file exists, it is loaded at 0×100 & kernel @ 0×8000
Else if disable_commandline_tags is set load kernel @ 0×0
Else if load kernel @ 0×8000 and put ATAGS at 0×100
See Issue 16 in https://github.com/raspberrypi/linux/issues
5. kernel.img, is the *first* thing that runs on the ARM
processor.

And more information on config.txt here

Finally I received my female/male cables for inter-board connects (my soldering skill is close to zero) and got FTDI-based TTL/USB converter work. I had more luck with it then with my old trusty TTL/RS232 converter. No garbage in linux output, serial input works for u-boot.

You can find content of boot partition of SD-card I use here.

Fully functional serial port means that boot-over-serial should work and I do not need to move SD-card between R-Pi and card reader to get new version of u-boot running. So based on this post I managed to automate compile/run/fix cycle to some extent. Not C-Kermit expert here, so the script is lame but it does its work:

#!/home/gonzo/bin/wermit

# Serial port setup.  These settings will likely need to be
# changed to match the configuration of your workstation
# and the ARM board you're working with.
set line /dev/ttyUSB3
set speed 115200
set serial 8n1

# General C-Kermit settings.  These probably don't need to change.
set flow-control none
set file type bin
set carrier-watch off
set prefixing all
set modem none

# load binary
input 90 "Raspberry-Pi # "
lineout "loadb 0x00000000"
# This should be the absolute path to your kernel uImage file.
send /home/gonzo/1/kernel.img

# This command drops you into a console where you can interact
# with the kernel.
connect

So now when I’m working on USB support for R-Pi the development cycle looks like this:

  • Hack-hack-hack, compile, generate kernel.img, place kernel.img to ~gonzo/1/
  • power-cycle board, run script
  • Press Enter to trigger file upload and wait for this:
    ## Total Size      = 0x0002b6d0 = 177872 Bytes
    ## Start Addr      = 0x00000000
    
  • Issue go 0 command
  • Issue usb start command, wait for results and start over