# Starting Tiny OS Development With HiFive1

**URL:** https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644
**Category:** General
**Created:** [September 30, 2018, 8:15pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644 "2018-09-30T20:15:42Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![davidpgil](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/davidpgil/32/1179_2.png) [@davidpgil](https://forums.sifive.com/u/davidpgil)
#### Post date: [September 30, 2018, 8:15pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/1 "2018-09-30T20:15:42Z")

</div>

Hello everyone, I was wondering if I could get some advice from the SiFive community.

I just purchased a HiFive1 with the intention of learning to develop for that and possibly create a tiny OS for it. I have no experience with this level of programming but I’m willing to do it for the fun of it and adventure.

My goal is bootstrap a mini operating system for me to create all sorts of apps and tools for me to use to create other things such as graphics and sound programs.

Do you have any advice for me in this endeavor?

---

<div class="post-metadata">

### Author: ![laanwj](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@laanwj](https://forums.sifive.com/u/laanwj)
#### Post date: [October 1, 2018, 8:04pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/2 "2018-10-01T20:04:03Z")

</div>

Mind that the HiFive1 has only 16kB of RAM for data (although there is plenty of flash). That doesn’t leave much in terms of OS abstraction, certainly not with a 32-bit processor. And certainly not if you want to do sound and graphics.

---

<div class="post-metadata">

### Author: ![davidpgil](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/davidpgil/32/1179_2.png) [@davidpgil](https://forums.sifive.com/u/davidpgil)
#### Post date: [October 1, 2018, 8:28pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/3 "2018-10-01T20:28:28Z")

</div>

When I said “Tiny” meant along the lines of a 16-Bit OS such as Windows 3.1 … I know that sound and graphics WOULD be limited. Thats kind of the point. I want to see what I can do in a really tiny space. I will learn a great deal about optimization and memory management along with everything thats involved in bootstrapping an OS. At first my OS will probably not even have graphics. However I do want to build in that direction.

---

<div class="post-metadata">

### Author: ![laanwj](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@laanwj](https://forums.sifive.com/u/laanwj)
#### Post date: [October 2, 2018, 6:15am UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/4 "2018-10-02T06:15:13Z")

</div>

This is not Windows 3.1 ballpark, computers had 640kB RAM by then, more like home computers like the MSX1 and other 80’s 8-bit computers.

If that’s your challenge that’s great, don’t mean to discourage you 🙂

(using RISC-V as essentially a 16-bit processor is a kind of interesting idea, you could get away with storing pointers as 16 bit)

---

<div class="post-metadata">

### Author: ![bruce](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/bruce/32/452_2.png) [@bruce](https://forums.sifive.com/u/bruce)
#### Post date: [October 2, 2018, 6:13pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/5 "2018-10-02T18:13:22Z")

</div>

However you’re in the territory of early Apple ][, Commodore 16 etc, which had some pretty powerful software. Better, because you have practically unlimited code size available in flash. And much more compact and powerful machine code.

Someone really needs to pull the flash-programming code out of OpenOCD and make a library from it. Then you could use the top 8 MB (or more) of flash as a file system. Maybe do software data paging 😉 (aka overlays)

---

<div class="post-metadata">

### Author: ![EdHalferty](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@EdHalferty](https://forums.sifive.com/u/EdHalferty)
#### Post date: [October 2, 2018, 6:23pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/6 "2018-10-02T18:23:01Z")

</div>

You can also use a few GPIO lines to connect the board to a SPI SRAM chip, but it’ll be slower to access.

---

<div class="post-metadata">

### Author: ![bruce](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/bruce/32/452_2.png) [@bruce](https://forums.sifive.com/u/bruce)
#### Post date: [October 2, 2018, 7:05pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/7 "2018-10-02T19:05:16Z")

</div>

Yeah, seems you can get 1 MB for a couple of bucks.

[https://www.digikey.com/product-detail/en/microchip-technology/23LC1024-I-SN/23LC1024-I-SN-ND/3543084](https://www.digikey.com/product-detail/en/microchip-technology/23LC1024-I-SN/23LC1024-I-SN-ND/3543084)

There are 2 MB ones for not much more, but minimum order I immediately found is for 400 of them.

The next step up would be a Raspberry Pi Zero with 512 MB for $5. It comes with a free ARM management CPU. Or, if you want something you can actually buy, a NanoPi Neo. Nice peripherals 🙂

---

<div class="post-metadata">

### Author: ![laanwj](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@laanwj](https://forums.sifive.com/u/laanwj)
#### Post date: [October 2, 2018, 8:34pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/8 "2018-10-02T20:34:56Z")

</div>

> [@bruce](#):
>
> Someone really needs to pull the flash-programming code out of OpenOCD and make a library from it. Then you could use the top 8 MB (or more) of flash as a file system.

Oh wow, I never realized, so it would be possible to **write** the flash from the board itself?  
(I suppose so, switching to raw SPI mode while running from memory, which must be exactly what OpenOCD does, thinking about it)

> [@](#):
>
> Maybe do software data paging 😉 (aka overlays)

Overlays and manual paging, that sure brings back some memories.

> [@EdHalferty](#):
>
> You can also use a few GPIO lines to connect the board to a SPI SRAM chip, but it’ll be slower to access.

Nah it must be faster than using the host for storage over serial 🙂

---

<div class="post-metadata">

### Author: ![bruce](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/bruce/32/452_2.png) [@bruce](https://forums.sifive.com/u/bruce)
#### Post date: [October 2, 2018, 8:50pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/9 "2018-10-02T20:50:54Z")

</div>

> [@laanwj](#):
>
> Oh wow, I never realized, so it would be possible to write the flash from the board itself?
> 
> (I suppose so, switching to raw SPI mode while running from memory, which must be exactly what OpenOCD does, thinking about it)

Exactly. OpenOCD puts some SPI-writing code into SRAM and then runs it. There’s no reason any other program can’t do that too, it’s just the hassle of copying that code into SRAM temporarily (and making sure it’s PI or else simply linked for that address). Or you could just link it in SRAM as a kind of initialised globals that happens to be instructions, if you don’t mind the wasted space.

I’ve been hoping someone will do this for about the last 18 months, so I don’t have to do it 🙂 Copious spare time, and all that.

This is something that any self-respecting FORTH for the HiFive1 should be doing hint hint

---

<div class="post-metadata">

### Author: ![mhamrick](https://avatars.discourse-cdn.com/v4/letter/m/3ab097/32.png) [@mhamrick](https://forums.sifive.com/u/mhamrick)
#### Post date: [October 2, 2018, 9:50pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/10 "2018-10-02T21:50:02Z")

</div>

i actually did this for a customer. (code that runs in RAM and writes FLASH.) Megan describes the fespi driver in this post from way back when:

> [@How can I debug the HiFive board by JTAG?](http://forums.sifive.com/t/how-can-i-debug-the-hifive-board-by-jtag/649/4):
>
> Hi Huangwanneng, suggest that you first take a look at the RISC-V Debug Spec: And then you can look at the implementation of OpenOCD here: In particular, when the program is loaded to the SPI Flash, GDB’s load command examines the ELF file, sees that it linked in the Flash region, then requests OpenOCD to uses the appropriate driver to program the SPI Flash. For Freedom E platforms, that’s the fespi driver that we’ve also added to OpenOCD. OpenOCD is causing the processor to execute li…

i was also able to run TINY BASIC on the HiFive1, but still trying to figure out how to modify it to allow me to do GPIO twiddling.

---

<div class="post-metadata">

### Author: ![vhodges](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/vhodges/32/880_2.png) [@vhodges](https://forums.sifive.com/u/vhodges)
#### Post date: [October 3, 2018, 3:46am UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/11 "2018-10-03T03:46:19Z")

</div>

> [@bruce](#):
>
> Yeah, seems you can get 1 MB for a couple of bucks.

Note those are 1Mb (ie 128k) but still not too bad. I did come across a post on some Arduino bulletin board about a 6502 emulator that reads and writes to SPI ram (using the onboard ram as a cache) that I was interested in getting running on my HiFive, but alas other priorities and all that.

---

<div class="post-metadata">

### Author: ![davidpgil](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.sifive.com/davidpgil/32/1179_2.png) [@davidpgil](https://forums.sifive.com/u/davidpgil)
#### Post date: [October 3, 2018, 2:19pm UTC](https://forums.sifive.com/t/starting-tiny-os-development-with-hifive1/1644/12 "2018-10-03T14:19:13Z")

</div>

These answers while really cool and interesting are much much more than I need. Here are the actionable steps I think I should probably take based off of what was posted:

1. Learn the basics of Arduino and try to learn about writing an OS there, then run that on RISC-V
2. I need to learn fundamental stuff about how to approach writing an OS at all. I don’t have a computer science background.
3. I found a video on youtube where a guy is showing how to write an OS (called Chibi OS) on an Arduino. Maybe try that.
4. Writing a 16bit app on RISC-V seems possible. Thumbsup.
5. I wish programmers were willing to keep it simple and stupid when explaining things but I think its hard to de-abstract heavily abstracted topics. Takes more effort.

Thanks for all of your input. I’ll get cracking this weekend.
