u-boot flash emmc ttl serial - linux

I used to update firmware on embedded system through tools like tftp (with ethernet port or ethernet over usb), sd card or a simple usb stick.
I am currently working on a system without ethernet port, no usb port. Only a ttl/usb connexion to be able to access the console and a micro usb to supply it. I am currently building a linux image and a rootfs. The storage used on the board is emmc.
Is there a standard way to update linux/rootfs in Emmc, etc.. with u-boot by using a simple ttl/usb connexion ? I guess that I can part my flash in u-boot thanks to mmc command but I don't understand how to transfer my kernel image and my rootfs in emmc with a simple ttl/usb link.

Is there a standard way to update linux/rootfs in Emmc, etc.. with u-boot by using a simple ttl/usb connexion ?
Yes, when only the serial console connection is available, a binary transfer protocol can be employed. These methods are identical to what is used with phone modems.
A U-Boot command for one transfer method is loadb.
=> help loadb
loadb - load binary file over serial line (kermit mode)
Usage:
loadb [ off ] [ baud ]
- load binary file over serial line with offset 'off' and baudrate 'baud'
=>
Another U-Boot command for a transfer method is loads for binary data formatted as a Motorola S-record file:
=> help loads
loads - load S-Record file over serial line
Usage:
loads [ off ] [ baud ]
- load S-Record file over serial line with offset 'off' and baudrate 'baud'
=>
These methods of course require the appropriate sending program on the other end of the serial link, just like tftpboot requires a TFTP server. A decent terminal emulator program, such as Minicom or TeraTerm, can perform the PC side of these transfers. Note that it's the sender that determines the file to transfer; the U-Boot side cannot request the file by name but only receives it.
If these commands are not already available in your U-Boot, then you'll have to edit the configuration and rebuild U-Boot.

Related

Linux tool to send a SET_CONFIGURATION message to a device connected to the USB bus

I have developed a kernel driver for a USB device. Such a device has some pins that can provide functionality both as CDC ACM serial port or as input buttons. So to implement that I had to use two different USB configuration descriptors.
The driver works as expected, but I have to hardcode the chosen setup before compiling and loading the firmware to the micro-controller. I am searching a mechanism to change that device configuration from userspace.
I read about a SET_CONFIGURATION message on USB documentation, but coudn't find any Linux tool to send such kind of standard USB messages from userspace to the USB bus.
Does some of you (with more experience on this topic) know some userspace Linux tool to send a SET_CONFIGURATION message to a device connected to the USB bus?
Thanks in advance! :)
The function libusb_set_configuration() in LibUSB could do that in theory, but there is no need.
One can simply put both HID (for the button) and CDC (serial port) into one configuration using an "Interface association descriptor" (IAD).
This github repo resolves my issue:
https://github.com/avtolstoy/usbtool
No need for any special tools. You can simply do it via sysfs:
Find your device cd /sys/bus/usb/devices/X-Y/ where X is the bus number and Y is the device number.
Edit bConfigurationValue e.g., using sudoedit
Set the file contents to the desired configuration number and save it
That’s it!

How can BeagleBone Black be used as Mass Storage Device?

Is it possible to use the BB as Mass Storage Device?
I want it to be connected to an audio player that can read files from USB connectivity (such as USB flash drive) and act as data storage device containing one specific folder (and its sub-folders) from the file system (if possible, on a flash drive connected to the board.).
As the device specs says, it has connectivity of:
USB client for power & communications
USB host
Operating system will probably be Ubuntu but can be changed.
What drivers or configurations needs to be done in order to achieve this?
The latest images have already the mass storage usb gadget active, so a mass storage peripheral should be recognized by your system upon connection.
A quick google search reveals this discussion about a user trying to disable the USB MS gadget:
From the discussion, the files where the magic happens are:
Debian: /opt/scripts/boot/am335x_evm.sh
Ubuntu: /opt/scripts/boot/am335*
Armstrong: /usr/bin/g-ether-load.sh
In my Debian image the line you want to modify is:
modprobe g_multi file=${gadget_partition} cdrom=0 stall=0 removable=1 nofua=1 iSerialNumber=${SERIAL_NUMBER} iManufacturer=Circuitco iProduct=BeagleBone${BLACK} host_addr=${cpsw_1_mac}
and the corresponding $gadget_partition variable that is set just before that in order to customize the folder you want to expose.
Note that the g_multi gadget in its standard configuration presents 3 different devices: an ethernet interface, a mass storage peripheral and a serial interface. If you want to customize the parameters you can refer to the g_multi documentation (kernel.org)

Upload firmware from Flash using U-Boot

I have a problem. My system is an embedded Linux plaform. I am connecting to my board using serial port and I can access U-Boot.
I need to extract the complete firmware residing in flash through the console or through Ethernet. It looks like downloading is easy using TFTP or serial (Kermit, etc), but uploading it to the host PC for backup isn't obvious.
Does anyone know how this can be done?
Assuming that you are using NAND flash and U-Boot 2013.07 or similar:
Use the nand info command to see the NAND device names, sizes and erase block sizes for each NAND device that U-Boot detects
Use the nand read command to read from the NAND into RAM. How much NAND to read into RAM depends on the RAM size
If you have an SD (MMC) drive you can write from RAM to SD using the mmc write command
If you have a USB device you can use start usb to scan the USB for a mass storage or "ethernet" (i.e. OTG) device
If start usb detects a mass storage device, you can write from RAM to the mass storage device using the usb write command
There is no way to transfer from RAM to a USB or Ethernet network connection
Use the md command to hex dump arbitrary size block of memory to the serial line, then use some program to translate the ASCII hex back into binary
If you're willing to rebuild uboot and reflash your board, you can enable the tftpput command with the CONFIG_CMD_TFTPPUT option. (Assuming a recent version of uboot.)
Assuming not, within the embedded Linux, you can access your flash through /dev/mtd* (cat /proc/mtd to see the partitions). You can use dd to copy a partition to a ramdisk file, then use cat to combine the files into a single image, and the use ftpput to send it to your host. (This assumes that your embedded busybox has been built with these commands.)

How do I intercept messages from a USB device on Linux?

I have a popular drawing tablet that I connect to my PC with USB. Once connected, the tablet detects hand movements and manipulates the pointer accordingly. Somewhere, the tablet is transmitting this data to my computer.
My goal is to intercept these transmissions and manipulate the mouse after I process the data. The buzzwords I have found are: device drivers and HID, but I haven't been able to piece together much more than that.
Assuming this is possible, I have a few questions:
How is this done if the data format is known?
How is this done if the data format is unknown/proprietary?
My computer is running Ubuntu (but answers related to any form of a Linux OS are greatly appreciated!).
Note: This question is similar but intended for Windows.
Actually you missed a buzzword "USB sniffing". ;-)
Here are a few tutorials on USB sniffing on Linux, to get you started.
Official Wireshark wiki for USB monitoring
biot.com/blog/usb-sniffing-on-linux (InternetArchive)
tjworld.net/wiki/Linux/Ubuntu/USBmonitoring
Essentially you use the usbmon Linux kernel module to capture the USB-packets and Wireshark as a front-end to display and analyse the captured USB stream.
To add another useful resource: Kernel manual for usbmon
You can use the following commands on Debian Linux to view debug log for usbmon in text format using usbmon Kernel's built in usb monitoring:
$sudo -i to use root
#modprobe usbmon
#ls /sys/kernel/debug/usb/usbmon to view bus sockets
#cat /sys/kernel/debug/usb/devices to view devices at each bus socket
#cat /sys/kernel/debug/usb/usbmon/<bus socket> to view or you can route stdout to a file using >

howto send data to (linux based) embedded system

i got a Linux Kernel from http://www.at91.com/linux4sam/bin/view/Linux4SAM/LinuxKernel running on my ARM board.
I have a connection through serial port to my host system windows,
i also got a SAM-ICE JTAG debugger device.
so how can i send some data from my windows to my embedded linux?
It's depends on your at91 controller. Most at91 has two UARTS (some at91 has also Ethernet port). You can use second UART to send your data.

Resources