I o TM igrator: LLM -driven Embedded I o T Code Migration across Different OS es for Cloud-device Integration (2025)

Abstract: The increasing prevalence of embedded systems has necessitated manufacturers to migrate product code, transferring existing products to new embedded operating systems (OSes) for getting better compatibility and performance. Since manufacturers’ product code predominantly employs the Thing Specification Language (TSL) paradigm for cloud connectivity, migrated code consequently adheres to the same TSL standard. However, embedded code migration under the TSL paradigm proves more complex than conventional code migration. Neither outline-based code generation nor common code translation techniques can adequately address this challenge, despite their prevalence in existing systems. There exists a growing demand for a algorithm tailored to TSL paradigm embedded code migration. In response to this demand, we have developed IoTMigrator that employs a multi-agent pipeline to handle the issue. The key insight of our algorithm is the TSL enhancer, specifically designed for the characteristics of the TSL paradigm, which serves as a crucial component in the agent pipeline.To demonstrate the superiority of our algorithm, we have established our own benchmark, which includes six tasks across two OSes, RIOT and Zephyr. We adopted two key metrics: compilation pass rate and task completeness score. The experiment results show that our algorithm outperforms the baseline by an average of at least 50.5% for pass rate and 13.0% for completeness across all tasks in RIOT, and at least 83.4% for pass rate and 18.4% for completeness in Zephyr. This work will be open-sourced in the future.

## introduction to allow embedded devices to connect to cloud platforms, cloud platforms have introduced thing specification language (tsl) paradigm @xcite . there are now no fewer than 10 types of tsl models, such as alibaba cloud tsl @xcite , tencent cloud tsl @xcite , @xcite , and so on. these tsls include detailed specifications of device properties, events, services, etc. device manufacturers must program according to the specific content of the different cloud platforms' tsl, enabling their devices to access the cloud platform. to implement the various functions of tsl, programmers need to possess a certain understanding of tsl and a certain level of embedded oses programming. now, a growing number of manufacturers need to be compatible with other new embedded oses to keep up with the trend. for example, midea @xcite announced its support for harmony os to embrace the harmony os ecosystem. thus the challenge of how to efficiently enable embedded devices to implement newly emerging oses is a meaningful issue. the breakthroughs of llms (openai, 2023a), which have not only captured the attention of both academic and industrial communities but also revolutionized cross-os code migration. traditional code generation methods, such as outline-based code generation @xcite that first generate an outline and then produce code based on the outline, as well as code translation algorithms @xcite ) that translate algorithmic problems into languages like c++ or java, have both demonstrated outstanding performance. however, traditional code generation based on outline or code translation with llms cannot address code migration for embedded oses well. as shown in fig. 1 , the outline-based approach used the wrong libraries. since the @xmath0.@xmath1.@xmath2, leading the llm to mistakenly believe that the code for riot-os should also use the corresponding libraries @xmath3.@xmath4.h>. to better prove our claim, we show the statistics result with the gpt-4o, which includes direct method and few shot method across riot and zephyr oses. among them, the few shot method utilizes the communication templates we provided to reduce programming complexity. the accuracy rates of both methods are notably low, with the direct approach's rate being virtually zero (we consider accuracy rates below 1% as zero). moreover, the task completeness of llmgenerated code is insufficient as llm often uses place holders and simulation data (as shown in fig. 1 functionality, traditional methods don't generation the true code to read data from dht11 but generation the simulation temperature and humidity data). on the other hand, the code translation is typically applied to algorithm programming where the output varies based on different inputs and can be debugged through variable tracing. in contrast, embedded programming frequently operates without conventional inputs since it primarily reads sensor data rather than inputs provided by users. consequently, the conventional code translation methods are not suit for the embedded programming well. confronted with these challenges, recent work explores how to better leverage llms for code migration or generation. some scholars have proposed multi-agent collaborative framework @xcite , tool-using code generation @xcite , and so on. nevertheless, none of these methods can effectively accomplish the task of code migration. this is mainly due to the following reasons: 1 ⃝. the misleading influence of reference code provided by users. embedded oses often have more low-level code while the reference code tends to be higher-level, such as arduino. errors may ensue if an llm is affected by the reference code as llm uses reference code's libraries during migration. library errors can lead to a series of subsequent function errors and ultimately compilation failure. moreover, some operations required by arduino may not be necessary in others, for example, some embedded os libraries such as riot os don't require connecting to wifi in the code while arduino does. 2 ⃝. task completion may be compromised during code generation. for embedded code, it generally has weaker encapsulation than high-level languages, making it significantly more challenging for llm to generate successfully compiled code. consequently, llm needs an iterative process to ensure the code can compile successfully. however, during the iterative process, the llm may progressively simplify the code by stripping out functionality to overcome compilation challenges. although this approach may eventually yield successfully compiled code, it often comes at the expense of significantly decreasing functional completeness. to address these issues, we propose for the first time an embedded code migration strategy, named iotmigrator. we design a multi-agent pipeline specifically tailored for tsl's unique characteristics. the multi-agent pipeline consists of three agents: outline generator, tsl enhancer and code generator. the three agents each serve distinct functions: outline generator mitigates the impact of the reference code, tsl enhancer enhances task functional completeness by processing tasks according to tsl's unique characteristics, code generator generates the target code. given the current absence of open-source benchmarks for embedded systems, particularly those employing the tsl paradigm, we build a corpus comprising six typical products both in riot and zephyr oses. additionally, our experimental design evaluates compilation pass rate and task completeness score. our algorithm demonstrates significant improvements, achieving an average increase of 138.9% in compilation pass rate in riot and 342.7% in zephyr. for task completeness score, it shows consistent enhancements with average improvements of 26.7% in riot and 27.6% in zephyr. ## design we propose a system comprising three collaborative agents, as shown in fig. 2 . the three-agent pipeline operates as follows: (1) outline generator: it not only performs user code analysis to extract key information and code logic, but also generates sub-tasks. we record key information as metadata which includes key parameters (e.g. pin parameters, communication parameters) and key functions (e.g. pwm function and adc function). in addition, it extracts the reference code portion corresponding to the sub-tasks and summarizes the code logic. it ultimately generates a outline containing extracted metadata and sub-tasks. ## conclusion for the embedded code migration problem using the tsl paradigm, we have developed iotmigrator, a customized multi-agent pipeline solution specifically designed to leverage tsl's unique characteristics to address this challenge. our framework comprises three specialized agents: the outline generator extracts critical information and decomposes the task into subtasks; the tsl enhancer leverages tsl paradigm characteristics to separately handle communication and peripheral control subtasks; the code generator synthesizes the tsl enhancer's outputs into final executable code. in the last, we addressed the corpus scarcity challenge by constructing a dedicated benchmark, through which we evaluated performance using both compilation pass rates and task completeness score.