RetroBSD

2.11BSD operating system for microcontrollers
It is currently Sun Sep 15, 2019 9:05 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Tue Dec 08, 2015 9:39 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Long time back I was able (afaik) to compile binaries for retrobsd under UECIDE (and I uploaded them to retro's filesystem then).
Recently I've taken all the stuff over to SmallerC and it compiles fine.

Now, for LiteBSD, we do not have SmallerC.
How we can build our small stuff under UECIDE? (I want to avoid building under Linux environment).

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 9:55 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Not easy, LiteBSD is considerably more complex that RetroBSD.

I'm sure it can be done though, but creating a cross-compiler environment with all the required libraries and headers and such will be a challenge.

If you could clone me so that I have the ability to work on two things at the same time then I might find time to craft something. Or you could be adventurous and learn how to do it yourself ;)

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 10:37 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Ok, for time being, what is the easiest way under Ubuntu?
I do not want to mess with makefiles, libraries etc.
Simply to take my ie rc4.c source and bang.. 8-)

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 10:47 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
The makefiles are fully templated. A basic C program just needs a few lines to get it to compile:

Code:
PROG=   rc4
MAN6=   rc4.0

.include <bsd.prog.mk>


That will compile "rc4.c" into "rc4" and convert the manual page "rc4.6". Change 6 into whatever section the manual is in.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 1:12 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
So I created a new folder rc4 in usr.bin and placed my rc4_dropn.c into it:

Code:
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin$ cd rc4
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ ls
Makefile  Makefile~  rc4_dropn.c
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ make
Makefile:4: *** missing separator.  Stop.
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ bmake
bmake: don't know how to make /home/pito/LiteBSD/DESTDIR/usr/lib/libc.a. Stop

bmake: stopped in /home/pito/LiteBSD2/LiteBSD/usr.bin/rc4
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$

Makefile:
Code:
PROG=   rc4_dropn
MAN6=   rc4.0

.include <bsd.prog.mk>


rc4_dropn.c
Code:
// RC4 encryption/decryption
// RC4 stream ciphre, dropN modification
// rc4_dropn plaintext.file encryptedtext.file RC4key
//
// For example:
// rc4_dropn myfile encrmyfile QWERTY2387
// rc4_dropn encrmyfile myfile QWERTY2387
// Mind when the key is not uniformly distributed (ie. a passphrase), you should not be
// using it directly as the RC4 key. Instead, you should hash it first (preferably using a KDF)
// and use the result as the RC4 key.
// Maximum length of the RC4 key is 256 bytes.
//
// No warranties of any kind, provided as-is
// Pito 11/2013 and 10/2015 based on available sources

#include<stdio.h>
#include<stdlib.h>
#include<strings.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>

#define ARRAY_LENGTH   256

unsigned char s[ARRAY_LENGTH];
int rc4_i;
int rc4_j;

void swap(unsigned char *s1, unsigned char *s2) {
   char temp = *s1;
   *s1 = *s2;
   *s2 = temp;
}

void InitRC4(void) {
   int i;
   for(i=0 ; i < ARRAY_LENGTH; i++)
      s[i] = i;
   rc4_i = rc4_j = 0;
}

void DoKSA(unsigned char *key, int key_len) {
   int n;
   for(rc4_i = 0; rc4_i < ARRAY_LENGTH; rc4_i++) {
      rc4_j = (rc4_j + s[rc4_i] + key[rc4_i % key_len]) % ARRAY_LENGTH;
      swap(&s[rc4_i], &s[rc4_j]);
   }
   
   rc4_i = rc4_j = 0;

   for(n = 0; n < 1023; n++) {
      rc4_i = (rc4_i + 1 ) % ARRAY_LENGTH;
      rc4_j = (rc4_j + s[rc4_i]) % ARRAY_LENGTH;
      swap(&s[rc4_i], &s[rc4_j]);
   }
}

char GetPRGAOutput(void) {
   rc4_i = (rc4_i + 1 ) % ARRAY_LENGTH;
   rc4_j = (rc4_j + s[rc4_i]) % ARRAY_LENGTH;
   swap(&s[rc4_i], &s[rc4_j]);
   return s[(s[rc4_i] + s[rc4_j]) % ARRAY_LENGTH];
}

int main(int argc, char **argv) {
   FILE * file_to_encrypt;
   FILE * encrypted_output_file;
   unsigned char *encryption_key;
   int encryption_key_length;
   unsigned char data_byte;
   unsigned char keystream_byte;
   unsigned char encrypted_byte;
   int bytes_read = 1;
   
   if (argc < 4) {
      //printf("Too few arguments\n");
      exit(-1);
   }

   file_to_encrypt = fopen(argv[1], "rb");
   if(file_to_encrypt == NULL) {
      //printf("Cannot open file: %s\n", argv[1]);
      exit(-1);
   }
   
   encrypted_output_file = fopen(argv[2], "wb");
   if(encrypted_output_file == NULL) {
      //printf("Cannot open output file : %s\n", argv[2]);
      exit(-1);
   }

   encryption_key = (unsigned char *)argv[3];
   encryption_key_length = strlen((char *)encryption_key);

   if(encryption_key_length > ARRAY_LENGTH) {
      //printf("Key too large. should be <= 256 charachters\n");
      exit(-1);
   }

 
   InitRC4();

   DoKSA(encryption_key, encryption_key_length);

   while((bytes_read = fread(&data_byte, sizeof(char), sizeof(data_byte), file_to_encrypt)) > 0) {
      keystream_byte = GetPRGAOutput();
      encrypted_byte = data_byte ^ keystream_byte; 
      fwrite(&encrypted_byte, sizeof(char), sizeof(encrypted_byte), encrypted_output_file);      
   }
   
   fclose(file_to_encrypt);
   fclose(encrypted_output_file);
   return 1;
}

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 1:58 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
You have to have a fully build LiteBSD tree *before* you can build your application. Otherwise things like the standard libraries don't exist.

And yes, use bmake, not make.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 2:10 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Hmm, did I build kernel only before?? Maybe..
Now I get:
Code:
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ bmake
/usr/local/mips-2014.05/bin/mips-sde-elf-gcc -mips32r2 -EL -msoft-float -nostdinc -Werror -Os -I/home/pito/LiteBSD/DESTDIR/usr/include  -nostdlib -nostartfiles -L/home/pito/LiteBSD/DESTDIR/usr/lib  -T /home/pito/LiteBSD/DESTDIR/usr/lib/elf32-mips-le.ld  -Wl,-z,max-page-size=4096 /home/pito/LiteBSD/DESTDIR/usr/lib/crt0.o  -o rc4_dropn /home/pito/LiteBSD2/LiteBSD/usr.bin/rc4/rc4_dropn.c  -lc -lgcc
bmake: don't know how to make rc4.0. Stop

bmake: stopped in /home/pito/LiteBSD2/LiteBSD/usr.bin/rc4
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$

I see the binary there, 24kB. So I will remove the MAN stuff..
Code:
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ ls -l
total 40
-rw-rw-r-- 1 pito pito    58 Dec  8 15:20 Makefile
-rw-rw-r-- 1 pito pito    57 Dec  8 15:18 Makefile~
-rwxrwxr-x 1 pito pito 23823 Dec  8 15:21 rc4_dropn
-rwxrw-rw- 1 pito pito  2531 Dec  8 15:20 rc4_dropn.c
-rwxrw-rw- 1 pito pito  2531 Dec  8 15:00 rc4_dropn.c~
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$

With commented out MAN stuff I still see an issue:
Code:
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$ bmake
/usr/local/mips-2014.05/bin/mips-sde-elf-gcc -mips32r2 -EL -msoft-float -nostdinc -Werror -Os -I/home/pito/LiteBSD/DESTDIR/usr/include  -nostdlib -nostartfiles -L/home/pito/LiteBSD/DESTDIR/usr/lib  -T /home/pito/LiteBSD/DESTDIR/usr/lib/elf32-mips-le.ld  -Wl,-z,max-page-size=4096 /home/pito/LiteBSD/DESTDIR/usr/lib/crt0.o  -o rc4_dropn /home/pito/LiteBSD2/LiteBSD/usr.bin/rc4/rc4_dropn.c  -lc -lgcc
bmake: don't know how to make rc4_dropn.0. Stop

bmake: stopped in /home/pito/LiteBSD2/LiteBSD/usr.bin/rc4
pito@UBU1404:~/LiteBSD2/LiteBSD/usr.bin/rc4$

PS: We can start to mess with double precision now, cannot we?? :P

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 3:08 pm 
Contributor

Joined: Mon Nov 12, 2012 1:34 pm
Posts: 1092
Hi Pito,

Well, the MIPS code itself 'should' just run. I wonder if a simple "hello world" compiled under RetroBSD will actually run under LiteBSD?

I still like the idea of running Retro under LiteBSD. Or just porting Retro to the MZ. But we really do need to get the MMU working properly (maybe it already does)?

Lots of fun :).

Wiz


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 3:57 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Wiz, there is a HUGE amount of difference between LiteBSD and RetroBSD.

As much difference as between Mac OS X and Windows. They both run on Intel CPUs, but you cannot run software on one on the other.

Why?

Because the operating system is different.

In a computer program (which is what you have with a Retro- or LiteBSD program) the actual program file is only a tiny fraction of the actual program. The rest resides in shared libraries (LiteBSD, not RetroBSD) and system calls (kernel - completely different between the two).

You REALLY need to lose the mindset that you are programming a microcontroller! You aren't! You're programming an OPERATING SYSTEM. It's purely incidental that it runs on a PIC.

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 5:18 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
So I did it in hardway:
Code:
# ls
debug.log       teraterm488.exe
# kermit -r
Return to your local Kermit and give a SEND command.

KERMIT READY TO RECEIVE...

# ls -l
total 460
-rw-r--r--  1 root  wheel  428813 Oct 25 01:48 debug.log
-rw-r--r--  1 root  wheel   23823 Dec  8 10:10 rc4_dropn
-rw-r--r--  1 root  wheel   10610 Oct 25 01:48 teraterm488.exe
# chmod +x rc4_dropn
# ./rc4_dropn debug.log encr.log qwerty
# ls -l
total 884
-rw-r--r--  1 root  wheel  428813 Oct 25 01:48 debug.log
-rw-r--r--  1 root  wheel  428813 Oct 25 03:00 encr.log
-rwxr-xr-x  1 root  wheel   23823 Dec  8 10:10 rc4_dropn
-rw-r--r--  1 root  wheel   10610 Oct 25 01:48 teraterm488.exe
# ./rc4_dropn encr.log debug1.log qwerty
# ls -l
total 1308
-rw-r--r--  1 root  wheel  428813 Oct 25 01:48 debug.log
-rw-r--r--  1 root  wheel  428813 Oct 25 03:00 debug1.log
-rw-r--r--  1 root  wheel  428813 Oct 25 03:00 encr.log
-rwxr-xr-x  1 root  wheel   23823 Dec  8 10:10 rc4_dropn
-rw-r--r--  1 root  wheel   10610 Oct 25 01:48 teraterm488.exe
# wc debug.log
   17276   38996  428813 debug.log
# wc encr.log
    1633    9683  428813 encr.log
# wc debug1.log
   17276   38996  428813 debug1.log
# diff debug.log debug1.log
# diff debug.log encr.log
Binary files debug.log and encr.log differ
#


Code:
#
# dd bs=1k count=8000 if=/dev/zero of=AAA
8000+0 records in
8000+0 records out
8192000 bytes transferred in 8 secs (1024000 bytes/sec)
# time ./rc4_dropn AAA BBB qwerty
      138.88 real       138.71 user         0.00 sys
# time ./rc4_dropn BBB CCC qwerty
      139.06 real       138.86 user         0.00 sys
# time diff AAA BBB
Binary files AAA and BBB differ
        0.08 real         0.00 user         0.00 sys
# time diff AAA CCC
       12.20 real        12.16 user         0.00 sys
#


PS: it seems the time shows a wrong value = 0.00

PPS: interesting observation - 58.9kB/sec encryption speed with LiteBSD (200MHz, 50MHz sdcard).

What was the value with retrobsd (SmallerC) ?
Hmmm:
Code:
# dd bs=1k count=1024 if=/dev/zero of=myfile
1024+0 records in
1024+0 records out
# time ./rc4 myfile encfile QWERTY1234
        8.2 real         4.8 user         3.1 sys
# time ./rc4 encfile myfile1 QWERTY1234
        8.5 real         4.8 user         3.1 sys

That is 120.4kB/sec.
Something went wrong here.. :shock:
It should have shown something like 250kB/sec with LiteBSD, I would guess :? .

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Tue Dec 08, 2015 7:12 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
I double checked the timing and it is really 139seconds for 8MB to encrypt under LiteBSd..
Hmm.
Retrobsd 120kB/sec
LiteBSD 59kB/sec
The same source.. :?

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Wed Dec 09, 2015 11:55 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Mandelbrot "Seahorse Valley" location.
300x300 pixels means 270kBytes large .bmp created in ram. Then saved to file.
Slooow. Not sure float is double as of today. But is shows a picture at least :P
.bmp not allowed to post :)
Code:
# ./mandel 200 200 256  1779.803945297549 -0.7431533999637661 -0.1394057861346605 seah.bmp
# kermit
C-Kermit 5A(188), 23 Nov 92, 4.4 BSD
Type ? or HELP for help
C-Kermit>send seah.bmp
Return to your local Kermit and give a RECEIVE command.

KERMIT READY TO SEND...
C-Kermit>exit
# ls -l
total 17520
-rw-r--r--  1 root  wheel  8192000 Oct 25 03:08 AAA
-rw-r--r--  1 root  wheel  8192000 Oct 25 03:18 QQQ
-rw-r--r--  1 root  wheel   428813 Oct 25 01:48 debug.log
-rw-r--r--  1 root  wheel   428813 Oct 25 03:00 debug1.log
-rw-r--r--  1 root  wheel   428813 Oct 25 03:00 encr.log
-rwxr-xr-x  1 root  wheel    71504 Dec  9 16:14 mandel
-rwxr-xr-x  1 root  wheel    23823 Dec  8 10:10 rc4_dropn
-rw-r--r--  1 root  wheel   120054 Oct 25 03:52 seah.bmp
#

Attachment:
seah..JPG
seah..JPG [ 49.72 KiB | Viewed 10790 times ]

Code:
# ./mandel 300 300 1024  1779.803945297549 -0.7431533999637661 -0.1394057861346605 seah1.bmp
# ls -l
total 17788
-rw-r--r--  1 root  wheel  8192000 Oct 25 03:08 AAA
-rw-r--r--  1 root  wheel  8192000 Oct 25 03:18 QQQ
-rw-r--r--  1 root  wheel   428813 Oct 25 01:48 debug.log
-rw-r--r--  1 root  wheel   428813 Oct 25 03:00 debug1.log
-rw-r--r--  1 root  wheel   428813 Oct 25 03:00 encr.log
-rwxr-xr-x  1 root  wheel    71504 Dec  9 16:14 mandel
-rwxr-xr-x  1 root  wheel    23823 Dec  8 10:10 rc4_dropn
-rw-r--r--  1 root  wheel   120054 Oct 25 03:52 seah.bmp
-rw-r--r--  1 root  wheel   270054 Oct 25 04:23 seah1.bmp
#
Attachment:
seah1..JPG
seah1..JPG [ 110.8 KiB | Viewed 10790 times ]

The same 300x300x1024 - C under windoze:
Attachment:
seah1_C_Win.JPG
seah1_C_Win.JPG [ 98.62 KiB | Viewed 10780 times ]


The comparisons with Retrobsd shows Litebsd in this test is 6x slower than Retrobsd (15x slower clock to clock). I am not sure the LiteBSD's dev environment compiles double precision, though. Therefore, it is an indication only - as this Mandelbrot's test timing depends on the floating point math precision provided (the colors are representing the number of iterations done with floating point math).

The RC4 test shows Litebsd is 2x slower (5x slower clock to clock) - that test is using integers only (moreover, the Litebsd's sdcard write/read speed is 4x faster than Retrobsd's - thus the Litebsd's results are even worse).

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission