easyfind-client (Mouette)

Discuss development on Bubba
MouettE
Site admin
Posts: 257
Joined: 06 Oct 2011, 19:45

Re: easyfind-client (Mouette)

Post by MouettE » 11 Jan 2016, 21:45

Ahhh the wonders of C :)

So I looked it up and the code works on my b3 but not on my b2. Besides B2s have a redundant U-Boot environment so there are two positions in flash you need to read and based on the 5th byte decide which one is the active one (0: inactive; 1: active). I modified the source accordingly and tried to simplify it by loading the whole environment at once (64k on the b3, 8k on the b2 it's low enough) and reading strings from it.

Code: Select all

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

#include <stdio.h>

char* getkey() {

#if defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
    char env[8192];
    int fd = open("/dev/mtd0", O_RDONLY);
    lseek(fd, 0x50000, SEEK_SET);
    read(fd, env, 8192);
    if ( env[4] == 0x0 ) {
        lseek(fd, 0x60000, SEEK_SET);
        read(fd, env, 8192);
    }
    char *pos = &env[5];
#else
    char env[65536];
    int fd = open("/dev/mtd1", O_RDONLY);
    read(fd, env, 65536);
    char *pos = &env[4];
#endif
    close(fd);

    int l = strlen(pos);
    while ( l > 0 ) {
        if ( strncmp(pos, "key=", 4) == 0) {
            char* res = malloc(l - 3);
            strcpy(res, pos + 4);
            return res;
        }
        pos += l+1;
        l = strlen(pos);
    }
    return "";
}

int main() {
    printf("%s\n",getkey());
}
This code works well on both b3 and b2. I've included it in the easyfind-client source as a drop-in (see on github), please check it and I will make a release soon.

Gordon
Posts: 1324
Joined: 10 Aug 2011, 03:18

Re: easyfind-client (Mouette)

Post by Gordon » 12 Jan 2016, 14:01

Aha, additional complexity. That explains the 0x50000 segment mentioned earlier.

As said, I dislike the idea of reserving a lot of memory for loading the entire u-boot environment. Not so much for the single run version, because I'm not that freaky about it, but for the daemon. These machines are not big on memory and we cannot expand it to serve whatever we like it to do. My whole point of liking this client over the original python based daemon, and wanting to adopt it in my Bubba port to Gentoo, is that it should have a much smaller footprint (and be less CPU demanding at the same time). Adding a useless 64k (or 8k) to the image goes against what I'm after. Or does the key retrieval procedure not belong to the resident part of the TSR? I admit I did not investigate the code to that extend. Probably would resort to trial and error to find out, as it must have been over 25 years ago since I last created applications like this myself; in DOS, using a mix of Pascal and Assembly language. We used to have an additional goal back then, trying to fit as much as possible on a 360k (or 720k) floppy disk not to be a "disk jockey" (hard drives were for the insanely rich).

Good ol' days. Present day job I get confronted with software that uses a lot more memory and is a lot more CPU demanding while practically not outperforming applications that used to run on 4.77MHz machines. How bad a programmer do you need to be not to be able to allow users to actually experience the additional resources current hardware provides? This here little song did pull a smile to my face though when I discovered it:
https://www.youtube.com/watch?v=YRlPTbKHIPQ

MouettE
Site admin
Posts: 257
Joined: 06 Oct 2011, 19:45

Re: easyfind-client (Mouette)

Post by MouettE » 12 Jan 2016, 15:47

Gordon wrote:As said, I dislike the idea of reserving a lot of memory for loading the entire u-boot environment.
The env array is an automatic variable in the getkey function and thus is deallocated when the function returns. The only remain is the variable key which ... holds the key. The function is executed once on startup so this is not really an issue.

Post Reply