Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - novovaccum

#1
Modules Development / Module size
July 25, 2023, 07:39:43 PM
Hello,

As I was suggested not to load too large module into memory, I was actually wondering about memory limitation related to modules in ML .

I've been reading through the related topics :

From what I understand it all depends on the model of camera, but also how you are using ML : how many modules are loaded and how they will require memory depending on their needs as having too many modules or memory-intensive ones might result in throwing ERR70

In my case, using the 600D, I'm trying to figure out how much room is set for ML?

As Canon code doesn't know about ML and thinks he owns all memory pools to himself, what are the limitations (if identified)  ?

As I am using some external (configurable) library for my module, I'm concerned about those limitations.
Looking at the size of default modules, the biggest ones such as Lua or EDMAC are over 300k.
Should I consider this to be the limit?

Once again I know it relates mostly on the way things will be configured and how ML will be used but I cannot seem to wrap my head around that subject. And please let me know if this information was already available in the forum. I'll simply delete that post! :)

Thank you for your help! :)

#2
Hello,

I'm wrapping my head around, trying to figure out how I could access RAW and JPEG buffer during image acquisition...

I could get logs from SCSS states when a picture is being taken, following this topic : https://www.magiclantern.fm/forum/index.php?topic=1915.0

I was able to output the memory addresses when CreateStateObject returns, using the qemu logs for my 50D, also following : https://www.magiclantern.fm/forum/index.php?topic=17969.msg196010#msg196010

Then I decided to create a module to log trace the different states and transitions during the image aquisition, simply reproducing what seemed to by done in the shootspy.c example. I don't know if it was a good idea, but as I was not able to find that code from ML sources (neither on `dm-spy-experiments` branch), or maybe did I miss something...?


#include <string.h>
#include <dryos.h>
#include <module.h>
#include <property.h>
#include <menu.h>
#include <config.h>
#include <console.h>
#include "../trace/trace.h"
#include "state-object.h"

/* uncomment for live debug messages */
// #define trace_write(trace, fmt, ...) { printf(fmt, ## __VA_ARGS__); printf("\n"); msleep(500); }

#define STR_APPEND(orig,fmt,...) ({ int _len = strlen(orig); snprintf(orig + _len, sizeof(orig) - _len, fmt, ## __VA_ARGS__); });

#define LOG_SIZE 10000
static char logs[LOG_SIZE] = "";

/* to start tracing while module is enabled */
static uint32_t tranlogs_trace_ctx = TRACE_ERROR;

static CONFIG_INT("tranlogs.enabled", tranlogs_enabled, 0);

// https://www.magiclantern.fm/forum/index.php?topic=1915.0

/**
************************     
********** 50D *********
************************
*/
#define SCS_STATE (*(struct state_object **)0x320C)
#define SCSES_STATE (*(struct state_object **)0x3210)
#define SCSSR_STATE (*(struct state_object **)0x3214)
#define SBS_STATE (*(struct state_object **)0x3268)
#define SDS_REAR_STATE (*(struct state_object **)0x36E0)
#define SDS_FRONT1_STATE (*(struct state_object **)0x3750)

// #define SDS_FRONT2_STATE (*(struct state_object **)0x36B4) // not found
// #define SDS_FRONT3_STATE (*(struct state_object **)0x36B8) // not found
// #define SDS_FRONT4_STATE (*(struct state_object **)0x36BC) // not found

#define SPS_STATE (*(struct state_object **)0x32B0)
#define FSS_STATE (*(struct state_object **)0x3C94)

// #define FCS_STATE (*(struct state_object **)0x3c34) // not found

static int (*StateTransition)(void*,int,int,int,int) = 0;

static int counter = 0;

static int stateobj_spy(struct state_object * self, int x, int input, int z, int t)
{   
    int old_state = self->current_state;
    int ans = StateTransition(self, x, input, z, t);
    int new_state = self->current_state;

    if (self == SBS_STATE) { STR_APPEND(logs, "SBS "); }
    else if (self == SCS_STATE) { STR_APPEND(logs, "SCS  :"); }
    else if (self == SCSES_STATE) { STR_APPEND(logs, "SCSes:"); }
    else if (self == SCSSR_STATE) { STR_APPEND(logs, "SCSsr:"); }
    else if (self == SDS_REAR_STATE) { STR_APPEND(logs, "SDSr :"); }
    else if (self == SDS_FRONT1_STATE) { STR_APPEND(logs, "SDSf1:"); }
    // else if (self == SDS_FRONT2_STATE) { STR_APPEND(logs, "SDSf2:"); }
    // else if (self == SDS_FRONT3_STATE) { STR_APPEND(logs, "SDSf3:"); }
    // else if (self == SDS_FRONT4_STATE) { STR_APPEND(logs, "SDSf4:"); }
    else if (self == SPS_STATE) { STR_APPEND(logs, "SPS  :"); }
    else if (self == FSS_STATE) { STR_APPEND(logs, "FSS  :"); }
    // else if (self == FCS_STATE) { STR_APPEND(logs, "FCS  :"); }

    STR_APPEND(logs, "(%d) -- %2d -->(%d)\n", old_state, input, new_state);
    trace_write(tranlogs_trace_ctx, "%s", logs);
   
    return ans;
}

static int stateobj_start_spy(struct state_object * stateobj)
{
    if (!StateTransition)
        StateTransition = (void *)stateobj->StateTransition_maybe;
   
    else if ((void*)StateTransition != (void*)stateobj->StateTransition_maybe) // make sure all states use the same transition function
    {
        beep();
        return;
    }
  stateobj->StateTransition_maybe = (void *)stateobj_spy;
  return 0; //not used currently
}

static void shootspy_init(void* unused)
{
    logs[0] = 0;
    stateobj_start_spy(SCS_STATE);
    stateobj_start_spy(SCSES_STATE);
    stateobj_start_spy(SCSSR_STATE);
    stateobj_start_spy(SBS_STATE);
    stateobj_start_spy(SDS_REAR_STATE);
    stateobj_start_spy(SDS_FRONT1_STATE);
    // stateobj_start_spy(SDS_FRONT2_STATE);
    // stateobj_start_spy(SDS_FRONT3_STATE);
    // stateobj_start_spy(SDS_FRONT4_STATE);
    stateobj_start_spy(SPS_STATE);
    stateobj_start_spy(FSS_STATE);
    // stateobj_start_spy(FCS_STATE);
}

static struct menu_entry tranlogs_menus[] =
{
    {
        .name           = "Transition Logs Module",
        .select         =  menu_open_submenu,
        .help           = "Log State Machine transitions",
        .max            = 1,
        .submenu_width  = 710,
        .children       = (struct menu_entry[]) {
            {
                .name   = "Enable module",
                .max    = 1,
                .priv   =  &tranlogs_enabled,
                .help   = "Will be generated once camera restart"
            },
            MENU_EOL,
        },
    },
};


static unsigned int tranlogs_init()
{       
    char filename[32] = "STATES.TXT";
       
    if(1)
    {
        tranlogs_trace_ctx = trace_start("debug", filename);
        trace_set_flushrate(tranlogs_trace_ctx, 1000);
        trace_write(tranlogs_trace_ctx, "tranlogs module: Starting trace");
    }

    menu_add("Debug", tranlogs_menus, COUNT(tranlogs_menus));

    // main task during shoot
    task_create("shootspy_init", 0x1A, 0x1000, shootspy_init, (void*)0);
   
    return 0;
}

static unsigned int tranlogs_deinit()
{
    return 0;
}

MODULE_INFO_START()
    MODULE_INIT(tranlogs_init)
    MODULE_DEINIT(tranlogs_deinit)
MODULE_INFO_END()

MODULE_CONFIGS_START()
    MODULE_CONFIG(tranlogs_enabled)
MODULE_CONFIGS_END()


Then I could retrieve the following logs from the 50D :


FSS  :(0) --  7 -->(0)
SCS  :(1) --  1 -->(2)
SCS  :(2) --  2 -->(4)
SCS  :(4) --  3 -->(5)
SCS  :(5) --  4 -->(6)
SCSes:(0) --  5 -->(1)
FSS  :(0) --  8 -->(0)
SCSes:(1) -- 14 -->(2)
SCSes:(2) -- 15 -->(4)
SCS  :(7) --  6 -->(8)


I find it a bit difficult to figured out what is going on there. Is there some debug mode I should have enabled to access more detailed logs or is there some better way to retrieve more information on those transitions?

I must admit I'm fairly new to ML and it's code. I spent some fair amount of time reading through the forum and I could not find more information on the topic. If I've missed any information, please let me know.

Thank you for your precious help


#3
Hello,

I am a student in my last year of engineering school. For my diploma work I thought of using ML to develop a module to encrypt an image before it is written on the card. The idea is to use the https://doc.libsodium.org library to do so.

I've been working on this idea for a few weeks now, and I finally managed to link the cross-compiled library, but I'm now stuck with the calls related to the C standard library. (malloc, free, read, close, etc....).


Will NOT load on:
    5D2 (fcntl, malloc, read, free, abort, close, explicit_bzero, open)


I referred to this old post on the forum for a similar question about adding external libraries: https://www.magiclantern.fm/forum/index.php?topic=18897.msg179492#msg179492 Unfortunately most of the links are not available anymore.

I tried to follow the example in the LUA module with Dietlibc, but even if I reproduce the configuration and link the ".o" produced by Dielibc in the Makefile of the module in question, I cannot seem to solve the problem.

Or do I have to re-implement all methods in a wrapper such as "ml-lua-shim.c" ? Or is there a better way?

As I don't have any real knowledge in embedded system, I'm a bit stuck. So I apologize in advance if my questions do not seem relevant.

Thank you in advance for your help