1 of 30

Falling down from FreeBSD

RubyKaigi2021

Hiroki Mori

@yamori813

2 of 30

FreeBSD support of small devices

3 of 30

FreeBSD remove support of some devices

armv4 support deleted before 12R

armv5 support deleted before 13R

Admtek SoCs support deleted before 12R

Realtek is too old MIPS version. So it can't be ported.

4 of 30

Older module resources

FreeBSD need more than 32M bytes of RAM and 8M bytes of flash

8MB RAM is too small for FreeBSD

2MB flash is too small for FreeBSD

5 of 30

Is it really garbage?

It's real 32Bit architecure

It have Ethernet support

Chip is not broken

Power consumption is low

6 of 30

Save the earth!

Let's reduce garbage dumping

Protect nature

We have not so much resources

Rare metal recycling is conspiracy

We have no time

7 of 30

So I started mruby on YABM

8 of 30

Lightweight ruby language

Developed with C language

Almost fully written by matsumoto-san(matz)

For Embedded target

compile to bytecode and execute

Extend by C or Ruby code, named mrbgems

9 of 30

Bare Metal port

Not use any OS

Directly executed from boot loader

YABM is Yet Another Bare Metal

10 of 30

Targets

Realtek RTL8196C,E... (Lexra:MIPS I)

Broadcom BCM4712...(MIPS 4K)

Admtek ADM5120(MIPS 4K)

Kinden KS8695(ARMV4)

FreeBSD have Broadcom/mips support. But still not support network.

11 of 30

How to get target

Japanese great second hands shop named “Hardoff” have so many target

Every city have “Hardoff” shop

Only 110 yen or 330 yen

12 of 30

How to build

13 of 30

Development environment

Linux ELF toolchain on FreeBSD Linux emulation

FreeBSD Cross compiler Collection package

all gcc is version 4

All target bootloader support tftp firmware upgrade

Not support float

Reuse ZRouter.org knowledge

14 of 30

Used libraries

newlib (only libc)

lwip

bearssl

Header is important

15 of 30

How to build

16 of 30

Flash image

17 of 30

Boot sequence

bootloader copy VM image to memory then ...

18 of 30

Support devices

Interrupt Timer

Ethernet GPIO

UART Flash

I2C by GPIO bitbang

19 of 30

Bootloader

RTL8196C - Original

BCM4712 - CFE

ADM5120 - u-boot

KS8695 - u-boot

some bootloader build on FreeBSD Linux emulation

20 of 30

MMU support

Not using MMU on a MIPS target

On ARM SoCs use MMU, because of performance issue

Very slow fibonaccci benchmark no MMU because of no cache

but only use single mapping one-to-one addresses

ethernet buffer use on no cache memory

21 of 30

IoT

22 of 30

Network Support

Ethernet driver code reference boot loader, Linux or FreeBSD

all target support TCP/IP and TLS by BearSSL

support DHCP or static IP

support NTP, HTTP and HTTPS

support IPv6

not support of MQTT

23 of 30

Internet of Test

ThingSpeak provide free plan

I made weather station used I2C sensor

update 20 sec interval

24 of 30

Part of Script

val = @y.i2cread(BMPADDR, addr) << 8 | @y.i2cread(BMPADDR, addr + 1)

para = "api_key=" + APIKEY + "&field1=" + count.to_s + "&field2=" + btstr + "&field3=" + bpstr

res = SimpleHttp.new("https", "api.thingspeak.com", 443).request("GET", "/update?" + para, {'User-Agent' => "test-agent"})

25 of 30

With mruby on FreeBSD

26 of 30

Ouchi monitor (omon)

Used mips small module

Build mruby by ZRouter ports.

mruby on YABM post data to

mruby on FreeBSD by HTTP

27 of 30

Let’s start

28 of 30

How do I do ?

Go HardOff

check Qiita

checkout source code from github

29 of 30

Source code

30 of 30

Thanks ray,matz,friend

yamori813@yahoo.co.jp