Shop OBEX P1 Docs P2 Docs Learn Events
Getting started with Spinix — Parallax Forums

Getting started with Spinix

jazzedjazzed Posts: 11,803
edited 2014-06-20 06:33 in Propeller 1
Did you know that Dave Hein's Spinix090 has a Spin Compiler and Assembler?

Spinix is pretty amazing. Not sure how it is over-looked by this community.

The spinit Spin Compiler compiles *.spn to *.spa spasm (spin byte-code assembly).
The spasm Spin Assembler converts spin byte-code assembly into a spin program.
The spinit *.spn program is limited to one file, but there are several interesting demos.

Spinix090 comes with a fairly complete set of on-line documentation and Unix-like utilities.
Additionally, Spinix can run programs built with the PropellerTool or Propeller-GCC.

Future posts will build on this introduction.
«1

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:28
    Spinix Setup

    To succeed with the Spinix setup below, you will need a few things.
    Hardware Requirements:

    - Propeller Board with micro SD card slot like the ACTIVITYBOARD (4 pin SD card interface)
    - A microSD card and USB adapter (or other PC interface for file transfer)
    - USB Cable
    - Optional power supply for servo experiments

    Software Requirements:

    - The Spinix090 Package (latest as of this post). Latest Spinix seems to always get posted here.
    - Some kind of Serial terminal program capable of using USB at 115200 bps.
    - Propeller-Tool, BSTC, or some kind of loader.
    - Optional ANSI terminal program for PC for best experience like Putty. Putty for window here.
    - Optional Propeller-GCC
    Setup Procedure:

    1. Make sure you have required items above. Optional items are nice to have.
    2. Unpack the Spinix090 package to your computer.
    3. Use Propeller-Tool, BSTC, or other loader to program the Propeller board with Spinix/bootsd.eeprom.
    4. Insert SD card to computer, do a quick format as FAT32 (works best with 32KB Allocation size).
    5. Reinsert SD card if necessary.
    6. Copy Spinix/root/files to the SD Card.
    7. Safely remove SD Card and insert in the Propeller board.
    8. Start the terminal program for the serial port (for Putty, set Keyboard Backspace Control-H)
    9. Reset the Propeller board by pushing the button or power-cycle.

    10. Spinix should start with thie prompt "Press any key to start SD pin setup"
    On ACTIVITYBOARD:
    10.a. Enter DO pin number: 22
    10.b. Enter CLK pin number: 23
    10.c. Enter DI pin number: 24
    10.d. Enter DI pin number: 25

    11. Reset the Propeller board again and verfy the Spinix prompt shows something like this:
    spinix 0.90 April 8, 2012
    /$

    12. Enter "ls" to see files, then "ps" to see COG usage.
    /$ ls
    bin           demos         manpages      spasm         license.txt
    
    /$ ps
    # Type Mode Addr  Size Name
    - ---- ---- ---- ----- ----
    0 SPIN BACK 2b4c  9280 /bin/shell
    1 PASM DRVR 0000     0 serial I/O
    2 PASM DRVR 0000     0 SPI Driver
    3 SPIN BACK 5208 10688 kernel.binary
    4 SPIN FORE 1354  6132 /bin/ps
    
    /$
    
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:29
    Spinix offers many Linuxy built-in utility programs.
    /$ ls bin
    cat           cd            chmod         config        cp
    diag          diff          dos2unix      echo          ed
    grep          halt          head          kill          linefeed
    loadi2c       ls            man           mkdir         more
    mv            od            ps            pwd           rb
    reboot        rm            sb            shell         tail
    tar           ted           unix2dos      vi
    

    What do they do?

    Use the man program (manual) to find out. The ls program has already been used. Let's see what it does.
    /$ man ls
    LS(1)                          User Commands                            LS(1)
    
    
    NAME
            ls - list files
    
    
    SYNOPSIS
            ls [OPTIONS] [DIRECTORIES]
    
    
    DESCRIPTION
            List the files in the DIRECTORIES to the standard output.  If no
            DIRECTORIES are specified, the current directory is listed.  If OPTIONS
            is not specified, only the file names will be listed.  OPTIONS can be
            one or more of the following:
    
    
                -l - Long list that shows the attributes and lengths
                -a - Show all files including hidden files that start with . and _
                -e - Show the executable type
    
    
    AUTHOR
            Dave Hein
    
    
    COPYRIGHT
            Copyright (c) 2011, 2012, Dave Hein
            MIT License (See license.txt in the root directory)
            This is free software: you are free to change and redistribute it.
            There is no warranty, to the extent permitted by law.
    
    
    
    
    SPINIX utility                    March 2012                              LS(1)
    
    
    /$
    

    That's a man page. Other man pages are available and are in the manpage directory.
    /$ ls manpages
    cat.txt       cd.txt        chmod.txt     config.txt    cp.txt
    diag.txt      diaghelp.txt  diff.txt      dos2unix.txt  echo.txt
    ed.txt        edhelp.txt    getmod.txt    halt.txt      head.txt
    kill.txt      lerner.txt    linefeed.txt  loadi2c.txt   ls.txt
    man.txt       mkdir.txt     more.txt      mv.txt        od.txt
    ps.txt        pwd.txt       rb.txt        reboot.txt    rm.txt
    sb.txt        shell.txt     spasm.txt     tail.txt      tar.txt
    ted.txt       unix2dos.txt  vi.txt
    

    The man program can be used from anywhere in the directory structure.
    Another way to see the content of a file is by using $ cat.
    /$ cat manpages/linefeed.txt
    LINEFEED(1)                      User Commands                      LINEFEED(1)
    
    
    NAME
            linefeed - enable or disable linefeeds
    
    
    SYNOPSIS
            linefeed [PARM]
    
    
    DESCRIPTION
            The linefeed utility is used to enable or disable line-feeds when
            printing the newline character.  PARM can be either "on" or "off" to
            enable or disable line-feeds.
    
    
            The "config" command may also be used to perform a similar function.
    
    
    AUTHOR
            Dave Hein
    
    
    COPYRIGHT
            Copyright (c) 2011, 2012, Dave Hein
            MIT License (See license.txt in the root directory)
            This is free software: you are free to change and redistribute it.
            There is no warranty, to the extent permitted by law.
    
    
    
    
    SPINIX utility                    March 2012                        LINEFEED(1)
    
    
    /$
    
    

    The cat program concatenates the output of a file to the terminal. This example shows the linefeed utility. In linux and spinix both line-feed and carriage-return are printed. A terminal program like PST interprets both to mean new-line, so "$ linefeed off" tells spinix not to print line-feeds. Of course one can just disable line-feed in PST also.

    The cat program has another feature when combined with a pipe command line modifier.
    cd home
    /home$ cat > test.txt
    
    
    /home$ cat test.txt
    hello
    /home$
    

    What happened here? We created a new file called test.txt that contains "hello". Using cat > file, sends console text to the file. To stop cat, use CTRL+D.

    Why didn't the hello text show up when being typed? Dave?

    What is a pipe command line modifier ? Use "$ man shell" to find out. Pipe command line modifiers are built-in to the shell.
    /home$ man shell
    SHELL(1)                         User Commands                         SHELL(1)
    
    
    NAME
            shell - spinix shell program
    
    
    SYNOPSIS
            shell
    
    
    DESCRIPTION
            Provides the command-line interface for the spinix operating system.
            The shell program can execute the following commands:
    
    
                alias   - create an alias, such as ll="ls -l"
                set     - print the aliases that have been defined
                history - print a history of commands
                FILE    - execute FILE
    
    
            Executable files can be one of the following:
    
    
                - Relocatable spinix Spin application
                - spinix C application
                - Stand-alone Spin program
                - Stand-alone C program
                - script file
    
    
            The first line of a script file must start with "#shell".  A script file
            can be started at a specfic line by specifying the line number after the
            name.
    
    
            Standard I/O can be redirected by using the ">", "<" and ">>" comand-
            line modifiers.  A spinix Spin or C program can be run in the background
            by using the "&" command-line modifier.  The "&&" modifier can be used to
            kill the shell when runnning an application.  The shell will be restarted
            after the app terminates.
    
    
    AUTHOR
            Dave Hein
    
    
    COPYRIGHT
            Copyright (c) 2011, 2012, Dave Hein
            MIT License (See license.txt in the root directory)
            This is free software: you are free to change and redistribute it.
            There is no warranty, to the extent permitted by law.
    
    
    
    
    SPINIX utility                    March 2012                           SHELL(1)
    
    
    /home$
    

    There are many such utility commands. Many of them are very familiar to command-line linux users. All /bin utilities are fully documented.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:30
    Reserved for Spinix Precompiled Demos
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:33
    Reserved for Spinix Compiling Spin (.spn/.spa) programs with spinit and spasm.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:35
    Reserved for building Propeller-GCC programs to run on Spinix.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 18:37
    Reserved for Spinix shell scripting.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-06 20:49
    Spinix Setup tutorial has been added here.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-07 18:04
    Steve, thanks for your interest in spinix. It's been about a year since I worked on it. I did a little bit of work on developing an 80x25 VGA text display since I posted spinix090, but I've never posted that code. As I added more features to spinix the 32K hub RAM became harder to deal with. It will be nice when P2 is available with its larger RAM and higher speed.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-07 19:47
    Hi Dave.

    Indeed P2 will have more room ....

    Honestly, I started looking at this mainly because of the spasm spin byte-code assembler. It looks like a good intermediate language for other things.

    I suspect that all such solutions suffer from the same problem with 32KB of HUB RAM. There are always trade-offs to be made in such a tiny space.

    Perhaps some features could be sacrificed?

    While TVs and VGAs are interesting, there is a lot that can be done with just a serial embedded solution.

    I'm curious, was the spinit compiler designed from scratch?

    Thanks,
    --Steve
  • yetiyeti Posts: 818
    edited 2013-07-07 21:58
    jazzed wrote: »
    While TVs and VGAs are interesting, there is a lot that can be done with just a serial embedded solution.
    Yes... please don't abandon Spinix on Propeller-1 just because of a missing cute VGA-output... we can add that later... optionally... using a 2nd Propeller, a PC, bluetooth, ...
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-07-07 22:37
    Is spinix written in C or Spin?

    Looking back at the archive files in 2010, it is in Spin, but that was before C and XMM mode came along. If it is running out of space for VGA drivers, one solution might be to port it over to C and run it in XMM mode from an external SPI ram chip. Then you could allocate (say) 8k for cache, some memory for essential things, and still have most of the hub ram left over for a VGA or TV screen buffer.

    Many cool possibilities - I'll be following this thread with interest.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-07-08 04:10
    jazzed wrote: »
    While TVs and VGAs are interesting, there is a lot that can be done with just a serial embedded solution.
    This sounds appealing until you realize that to use the serial port you need a PC running a terminal emulator. If you have a PC, why not just get it to run the compiler/assembler and development environment as well? It seems like something like Spinix really most value when you can run it without a PC attached at all. Of course, you could use something like Vince Briel's PockeTerm as an interface to a VGA monitor and PS2 keyboard or even the terminal side of OBC's two Propeller Mini Computer.
  • max72max72 Posts: 1,155
    edited 2013-07-08 05:06
    Could it be interfaced to a remote PC or tablet/phone via serial bluetooth or wifi modules?
    With Forth it can be done and it is a nice solution.
    Massimo
  • yetiyeti Posts: 818
    edited 2013-07-08 05:09
    David Betz wrote: »
    This sounds appealing until you realize that to use the serial port you need a PC running a terminal emulator. If you have a PC, why not just get it to run the compiler/assembler and development environment as well?
    You can use any PC, notebook, netbook, PDA, smartphone and you only will need a terminal emulator.
    I think this is a big plus!
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-08 07:09
    @Steve, yes the spinit compiler was developed from scratch. It generates SPASM assembly, which is then processed by the spasm assembler. It was written in C and then converted to spin. It has quite a few limitations that I can't remember at this point, but it will compile simple Spin programs. It doesn't handle PASM. I have a separate program called qasm (Quick Assembler) that assembles PASM. If I get back to working on this I would write a script that would first run a Spin program through qasm, and then run it through spinit, and finally use spasm to generate an executable file. However, at this point it might be interesting to try to port the Open Spin compiler to the Prop.

    Some of the features of spinix could be sacrificed to better fit the 32K of RAM. spinix supports several types of executables, which include relocatable Spin programs that can be run with other programs. I think quite a bit of space could be saved if the relocatable programs were eliminated along with the resident kernel. The shell could be expanded to handle more scripting features, and maybe some of the common apps could be included such as ls and cat.

    @Dr_Acula, spinix is written mostly in Spin. There are a few demo programs that are written in C. spinix only knows how to run LMM C programs, but it should be able to run CMM programs also. It shouldn't be too hard to add XMMC programs that run from the SD card. LMM C programs can be written to run in a stand-alone mode or as an app that runs with the resident kernel. The main limitation with C programs is that they are not relocatable like Spin programs, and must be loaded at location 0. However, it is possible to run one C program along with the kernel and additional Spin programs at the same time. hub RAM is the main limitation.

    One thing that spinix does with C programs is that it patches in the command-line programs using argc and argv. This works with stand-alone programs and apps, and allows the programs to work like on a real Linux system.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-07-08 07:10
    yeti wrote: »
    You can use any PC, notebook, netbook, PDA, smartphone and you only will need a terminal emulator.
    I think this is a big plus!
    You can pretty much do that already if you install BST or SimpleIDE and you get a much better development environment than will ever be hosted directly on the Propeller.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 09:02
    Dave Hein wrote: »
    Some of the features of spinix could be sacrificed to better fit the 32K of RAM. spinix supports several types of executables, which include relocatable Spin programs that can be run with other programs. I think quite a bit of space could be saved if the relocatable programs were eliminated along with the resident kernel. The shell could be expanded to handle more scripting features, and maybe some of the common apps could be included such as ls and cat.

    To me the great values here are shell and spinit programming. A shell script can run any program on the sdcard with redirection. That means you get the ability to use much more than 32KB memory for propeller programs without needing XMM support. Having spinit adds to shell power by giving program access to propeller resources. Of course if you only need to read or write pins, then you can make tiny programs to do that.

    Having some conditional support in the shell would very useful - that could be traded for command history in a different shell. Fortunately, all the source appears to be in the package, so a shell with different features is certainly possible.

    Can spinit and spasm be run in spinsim? It might be a stretch, but could the whole package could run in spinsim?

    Thanks
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-08 09:46
    I have run spinix under spinsim in the past. The file system is simulated through the use of the mailbox at $1234000x. It's been a while since I ran it under spinsim, but it should still work. I'll look at it during my lunch hour.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-08 11:53
    Here's a bootsim.binary that runs spinix under spinsim. Copy it to the root directory of the spinix090 image and run "spinsim -b bootsim.binary" from the root directory. Unfortunately, it doesn't run stand-alone programs, but it will run apps OK. You can do an "ls -e" to determine if a file is an app or a stand-alone program. spasm and spinit are stand-along programs, so you won't be able to run them. The problem is that stand-alone programs are executed by running a small loader program in the high end of memory that talks to the SD SPI driver directly. I'll have to modify the loader programs to use the spinsim mailbox instead of the SPI driver. I should be able to do that tonight.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-08 12:06
    Dave Hein wrote: »
    Here's a bootsim.binary that runs spinix under spinsim. Copy it to the root directory of the spinix090 image and run "spinsim -b bootsim.binary" from the root directory. Unfortunately, it doesn't run stand-alone programs, but it will run apps OK. You can do an "ls -e" to determine if a file is an app or a stand-alone program. spasm and spinit are stand-along programs, so you won't be able to run them. The problem is that stand-alone programs are executed by running a small loader program in the high end of memory that talks to the SD SPI driver directly. I'll have to modify the loader programs to use the spinsim mailbox instead of the SPI driver. I should be able to do that tonight.

    Hi Dave. That works :)

    Running "programs" in addition to "apps" in spinsim would be very useful.

    Thanks!
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-09 15:45
    I looked at running spinix programs under spinsim, but it would require changing the file drivers in the programs to support the spinsim mailbox methods. I could do it in a day or so, but that's more work than I'd want to do on it right now.

    I posted spinix097 to the spinix thread. That version contains some work I did on a VGA driver about a year ago. The driver only supports a 32x15 text display, which is a bit low-res to use for a console. I had done some work on an 80x24 text display, but it uses 2 cogs and requires about 3K of hub RAM.

    I hadn't use spinix for a while, so it was kind of fun to play around with it again. For anybody that is familiar with Linux you'll find that spinix has a similar feel to it. I had forgotten how far I had gotten with spinit/spasm. It is quite usable at this point. Probably the next thing to add to it is multiple object support.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-09 16:31
    Thanks Dave.
  • KC_RobKC_Rob Posts: 465
    edited 2013-07-13 11:08
    jazzed wrote: »
    Did you know that Dave Hein's Spinix090 has a Spin Compiler and Assembler?

    Spinix is pretty amazing. Not sure how it is over-looked by this community.
    ...
    Future posts will build on this introduction.
    Cool indeed. Thank you, Jazzed (I'll be keeping an eye on this thread); and of course, thank you, Dave!
  • jazzedjazzed Posts: 11,803
    edited 2013-07-16 07:32
    Spinix Utility Demo tutorial has been added here.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-16 08:59
    Steve, I noticed you asked why cat doesn't echo keystrokes when doing "cat >file". Since I use stdout to do the echoing it all goes into the file. However, I noticed that the Linux' cat does echo to the console when the stdout is redirected. Linux' cat also reads the stdin using the line buffered mode with backspace editing enabled. spinix' cat reads the stdin one character at a time, and will write backspaces to the stdout. I'll make a note of changing cat to work like the Linux version.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-30 18:02
    Dave,

    Could you give a little description of how to make a pipe-able C program for spinix?

    I'd like to do this: $ program < junk.txt

    The program should just be able to read and echo junk.txt
    I'm able to read something from stdin on spinix by doing getchar() but can't pipe it in.

    Is it necessary to build pipe-able spinix programs in lmm mode?

    Also, what is the purpose of clkfreq ?
    I.E. propeller-load -s -D clkfreq=1347436867 hello1.elf

    I've tried building hello1.c, loading, and running without much success with cmm.
    Using lmm it seems to work fine.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-30 20:15
    A spinix app uses the kernel to provide console and file I/O. In the csrc directory there are two programs called hello1.c and hello2.c. There is also a file called SpinixSerial.c that interfaces to the kernel serial driver. It provides two types of interface routines, where one type is like the FullDuplexSerial tx and rx routines. The other type uses the PropGCC FileDriver struct. The program hello1.c uses the FDS type of calls, and hello2.c uses the FileDriver interface with the standard I/O routines.

    File redirection requires an interface to the that spinix kernel file driver using the FileDriver struct. I haven't done that yet, but it is on my todo list.

    It's good to hear that LMM apps still work. The spinix loader patches a few things into binary image, to set the initial stack value, and provide an exit routine. A few things have changed in the C startup code since I last worked on spinix, so I wasn't sure that LMM apps would still work. The issue with CMM apps is probably due to a difference in the locations that are patched by the loader. I'll look at that when I have a chance.

    The value of 1347436867 that is used for the clock frequency is equal to 0x50504143, which represents the ASCII string "CAPP". This is used to tell spinix that the file is a C app. Spin files use the string "SPIN". It was convenient to use the first 4 bytes in the file for this purpose, and the clock frequency isn't needed since it was already set up at boot time.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-30 22:02
    Hi Dave,

    Thanks for all those details.

    If you haven't guessed yet, I'm trying to get the LittleC interpreter to work in Spinix. The CMM binary of the LittleC interpreter has lots of head room without including file-system stuff. The LMM binary won't run on Spinix at all.

    I thought the easiest and smallest way to get a usable LittleC program running in Spinix would be to pipe the source program into the interpreter ... maybe not.

    Do you have an example CAPP C program that uses Spinix file IO services?

    Actually, it would be nice to know what other services Spinix offers and how new services might be added.

    Thanks,
    --Steve
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-31 07:04
    I haven't written the spinix FileDriver interface for PropGCC programs yet. I've only done a serial I/O interface, which is in csrc/SpinixSerial.c. One thing that I really need to do is document how spinix works. The spinix file driver for Spin is located in src/cfileio_os.spin. It provides methods for fgetc, fgets, fopen, fread, and so on.

    Each method calls RemoteFunctionCall passing a command number and a pointer to the parameter list. The RemoteFunctionCall method waits for the system file lock to be cleared, and then puts the command number and parameter pointer in the kernel mailbox. It then waits for the function to be complete, and returns a return value. The mailbox location as well as other system information, such as the process table are located at high memory. The locations are defined in sysdefs.spin.

    With all that being said, I think the easiest way to run the LittleC interpreter under spinix is to run it as a stand-alone program. You just need to compile it with a clock frequency between 80 MHz and 100 MHz. That's how spinix detects stand-alone programs. If you want to get commands from an file you would need to build LittleC with the standard PropGCC file drivers. From spinix you would then type "littlec junk.txt", and spinix will pass the argument list to the program using argc and argv. You could use the technique that I used in the PropGCC filetest program to open a file and use it as stdin.

    EDIT: Look at filetest/filetest.c in the spinix source tree. It is essentially the same as the PropGCC demo program except that it calls a GetConfig program to get the SD pin assignment and a pointer to the current working directory string. It then calls LoadSDDriver, dfs_mount and chdir using the pin assignment and CWD string. I don't think this will work any more because dfs_mount was changed since I wrote this. I'll look into it.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-19 22:39
    Since space on the Propeller1 is still an issue with Spinix, I am wondering if porting a re-edit of Linux's Busybox in GCC into a file that can be called from th Propeller's SDcard might be a useful shift in strategy.

    http://www.busybox.net/about.html

    I am aware that there are some utilities that are Spinix specific and NOT compatible with the Linux/UNIX file system and the SDcard is a FAT file system. But a great deal of effort has gone into making Busybox a wonderfully small code footprint that offers the most utilities it can for Linux embedded systems. The same approach for Spinix might be a win.

    There is also the FreeDos project that might offer more of the kind of utilites that a FAT file system desires.

    http://www.busybox.net/downloads/BusyBox.html

    Here is the detail listing of BusyBox utilites.

    http://www.busybox.net/downloads/BusyBox.html
Sign In or Register to comment.