2

I have an embedded Linux system that uses ramdisk boot so it has run time no persistent storage available (it does have Flash to store kernel and ramdisk).

The only connectivity is RS-232 serial login console. So I am limited by what is provided by its built in busybox. I want to retrieve the ramdisk, modify it, and rewrite the ramdisk. The kernel does not have Flash filesystem support built-in. The ramdisk partition size is about 10 MBytes. When all files in the user directory are deleted, the free ramdisk size is about 14 MBytes.

The command dd is available so I can copy the ramdisk partition to the ramdisk, and can write to the flash from a ramdisk file. flashcp is also available.

So my problem is now how to receive and send binary files through the RS-232 serial console?

I research the followings and none is useful for me:

  • Linux command to send binary file to serial port with HW flow control? on stackoverflow
  • Binary data over serial terminal on stackoverflow
  • Transferring files using serial console on k.japko.eu
  • File transfer over a serial line on superuser.com
  • How to get file to a host when all you have is a serial console? on stackexchange

Mostly because x/y/zmodem are not available in the busybox.

Any idea? Thanks!

Per the request, here's what I should have included in the first place.

Available u-boot commands:

U-Boot >?
?       - alias for 'help'
askenv  - get environment variables from stdin
base    - print or set address offset
bdinfo  - print Board Info structure
boot    - boot default, i.e., run 'bootcmd'
bootd   - boot default, i.e., run 'bootcmd'
bootm   - boot application image from memory
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
crc32_chk_uimage- checksum calculation of an image for u-boot
echo    - echo args to console
editenv - edit environment variable
env     - environment handling commands
exit    - exit script
false   - do nothing, unsuccessfully
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls   - list files in a directory (default /)
fatwrite- write file into a dos filesystem
go      - start application at address 'addr'
gpio    - input/set/clear/toggle gpio pins
help    - print command description/usage
i2c     - I2C sub-system
iminfo  - print header information for application image
imxtract- extract a part of a multi-image
itest   - return true/false on integer compare
loadb   - load binary file over serial line (kermit mode)
loads   - load S-Record file over serial line
loady   - load binary file over serial line (ymodem mode)
loop    - infinite loop on address range
md      - memory display
mdc     - memory display cyclic
mm      - memory modify (auto-incrementing address)
mw      - memory write (fill)
mwc     - memory write cyclic
nm      - memory modify (constant address)
printenv- print environment variables
reset   - Perform RESET of the CPU
run     - run commands in an environment variable
saveenv - save environment variables to persistent storage
saves   - save S-Record file over serial line
setenv  - set environment variables
sf      - SPI flash sub-system
showvar - print local hushshell variables
sleep   - delay execution for some time
source  - run script from memory
sspi    - SPI utility command
test    - minimal test like /bin/sh
true    - do nothing, successfully
usb     - USB sub-system
usbboot - boot from USB device
version - print monitor, compiler and linker version
U-Boot >

Available busybox commands:

BusyBox v1.13.2 (2015-03-16 10:50:56 EDT) multi-call binary
Copyright (C) 1998-2008 Erik Andersen, Rob Landley, Denys Vlasenko
and others. Licensed under GPLv2.
See source distribution for full notice.

Usage: busybox [function] [arguments]...
   or: function [arguments]...

        BusyBox is a multi-call binary that combines many common Unix
        utilities into a single executable.  Most people will create a
        link to busybox for each function they wish to use and BusyBox
        will act like whatever it was invoked as!

Currently defined functions:
        [, [[, addgroup, adduser, ar, ash, awk, basename, blkid,
        bunzip2, bzcat, cat, chattr, chgrp, chmod, chown, chpasswd,
        chroot, chvt, clear, cmp, cp, cpio, cryptpw, cut, date,
        dc, dd, deallocvt, delgroup, deluser, df, dhcprelay, diff,
        dirname, dmesg, du, dumpkmap, dumpleases, echo, egrep, env,
        expr, false, fbset, fbsplash, fdisk, fgrep, find, free,
        freeramdisk, fsck, fsck.minix, fuser, getopt, getty, grep,
        gunzip, gzip, halt, head, hexdump, hostname, httpd, hwclock,
        id, ifconfig, ifdown, ifup, inetd, init, insmod, ip, kill,
        killall, klogd, last, less, linuxrc, ln, loadfont, loadkmap,
        logger, login, logname, logread, losetup, ls, lsmod, makedevs,
        md5sum, mdev, microcom, mkdir, mkfifo, mkfs.minix, mknod,
        mkswap, mktemp, modprobe, more, mount, mv, nc, netstat,
        nice, nohup, nslookup, od, openvt, passwd, patch, pidof,
        ping, ping6, pivot_root, poweroff, printf, ps, pwd, rdate,
        rdev, readahead, readlink, readprofile, realpath, reboot,
        renice, reset, rm, rmdir, rmmod, route, rtcwake, run-parts,
        sed, seq, setconsole, setfont, sh, showkey, sleep, sort,
        start-stop-daemon, strings, stty, su, sulogin, swapoff,
        swapon, switch_root, sync, sysctl, syslogd, tail, tar, tcpsvd,
        tee, telnet, telnetd, test, tftp, tftpd, time, top, touch,
        tr, traceroute, true, tty, udhcpc, udhcpd, udpsvd, umount,
        uname, uniq, unzip, uptime, usleep, vconfig, vi, vlock,
        watch, wc, wget, which, who, whoami, xargs, yes, zcat
user1261470
  • 121
  • 1
  • 6
  • *"Mostly because x/y/zmodem are not available in the busybox."* -- Instead of negative descriptions and making us play a game of 20 questions, post the Busybox commands that are available. Do you boot with U-Boot? If so, then list its available commands also. – sawdust Jun 16 '17 at 19:41
  • *"The only connectivity is RS-232"* -- To be clear, you're claiming that there is no USB, no MMC or SDcard, no Ethernet? If the SBC fails to boot from flash, then how do you recover? IOW is there an alternate means of booting? – sawdust Jun 16 '17 at 19:53
  • So, and what the problem to add `rz`/`sz` to busybox? Just enable it in the Busybox's configuration file. – 0andriy Jun 16 '17 at 21:54
  • Hi sawdust, Thanks! including the u-boot commands reveals the answer to my question: loadb/loady. Thanks for the hints! – user1261470 Jun 17 '17 at 00:08
  • Hi 0andriy, now that it no longer matter, but for completeness, uploading the new busybox through the serial port poses the same challenge; and for that u-boot loady won't help. – user1261470 Jun 17 '17 at 00:10
  • Hi sawdust, if the SBC doesn't boot, it probably has to go back to the factor for reprogramming using JTAG – user1261470 Jun 17 '17 at 00:11

2 Answers2

5

In uboot you could use loady/loadx to get file from pc via uart.I usually use teraterm to send file.

The process should be this:

  1. run loady in uboot enter image description here
  2. use teraterm send data enter image description here
  3. the file is transfer to you device's memory located in 0x01000000.
Ezio
  • 1,076
  • 3
  • 13
  • 24
0

Independently I found a way to upload binary files through the Linux console and I'll document the steps here in case others find it useful since I had a hard time looking for this information on the net.

Here's the theory: change the console mode to raw so all the binary traffic are't interpretted as console command, e.g. ctrl-C. Turn off echo so it doesn't add extra serial traffic. Run tar to accept input from the stdin. Since ctrl-C won't work, and tar won't know when to terminate, use a background task to kill the login shell so you can login again to do your staff.

Steps:

  1. Create a script to run in the background. Change myvar variable so it kills the login shell after the transfer is complete. Currently 120 corresponds to 1200 seconds, sufficient for a 10 MBytes file. In addition edit the 808 to match your login shell PID:

create bg file:

myvar=120
while [ $myvar -gt 0 ]
do
    myvar=$(( $myvar-1 ))
    echo -e " $myvar \n"
    ls -l
    sleep 10
done
kill -9 808
  1. Launch the script in the background:

in console type:

source ./bg &
  1. Use stty to change console to raw mode and do not echo

in console type:

stty raw -echo
  1. Start tar to untar stdin. Note: I have to use ctrl-J since no longer work after the stty command

in console type and ends with ctrl-j, not :

tar zx -f - 1> 1.log 2> 2.log
  1. Start Teraterm to send binary file

  2. Wait for completion and the new login prompt

user1261470
  • 121
  • 1
  • 6