简体   繁体   English

基于Linux的固件,如何实现更新的好方法?

[英]Linux-Based Firmware, how to implement a good way to update?

I'm developing a linux-based appliance using an alix 2d13. 我正在使用alix 2d13开发基于linux的设备。

I've developed a script that takes care of creating an image file, creating the partitions, installing the boot loader (syslinux), the kernel and the initrd and, that takes care to put root filesystem files into the right partition. 我开发了一个脚本,负责创建映像文件,创建分区,安装引导加载程序(syslinux),内核和initrd,并注意将根文件系统文件放入正确的分区。

Configuration files are on tmpfs filesystem and gets created on system startup by a software that reads an XML file that resides on an own partition. 配置文件位于tmpfs文件系统上,并在系统启动时由读取驻留在自己分区上的XML文件的软件创建。

I'm looking a way to update the filesystem and i've considered two solutions: 我正在寻找一种更新文件系统的方法,我考虑过两种解决方案:

  • the firmware update is a compressed file that could contain kernel, initrd and/or the rootfs partition, in this way, on reboot, initrd will takes care to dd the rootfs image to the right partition; 固件更新是一个压缩文件,可以包含内核,initrd和/或rootfs分区,这样,在重启时,initrd会注意将rootfs映像dd到正确的分区;
  • the firmware update is a compressed file that could contain two tar archives, one for the boot and one for the root filesystem. 固件更新是一个压缩文件,可以包含两个tar存档,一个用于启动,另一个用于根文件系统。

Every solution has its own advantages: - a filesystem image will let me to delete any unused files but needs a lot of time and it will kill the compact flash memory fastly; 每个解决方案都有自己的优势: - 文件系统映像将允许我删除任何未使用的文件但需要大量时间,它会快速杀死紧凑型闪存; - an archive is smaller, needs less time for update, but i'll have the caos on the root filesystem in short time. - 存档较小,需要较少的更新时间,但我会在短时间内对根文件系统产生问题。

An alternative solution could be to put a file list and to put a pre/post update script into the tar archive, so any file that doesn't reside into the file list will be deleted. 另一种解决方案可能是放置文件列表并将前/后更新脚本放入tar存档中,因此任何不驻留在文件列表中的文件都将被删除。

What do you think? 你怎么看?

I used the following approach. 我使用了以下方法。 It was somewhat based on the paper "Building Murphy-compatible embedded Linux systems," available here . 这是有点根据的论文“构建墨菲兼容的嵌入式Linux系统”,可在这里 I used the versions.conf stuff described in that paper, not the cfgsh stuff. 我使用了那篇文章中描述的versions.conf东西,而不是cfgsh的东西。

  • Use a boot kernel whose job is to loop-back mount the "main" root file system. 使用启动内核,其作用是环回安装“主”根文件系统。 If you need a newer kernel, then kexec into that newer kernel right after you loop-back mount it. 如果你需要一个更新的内核,那么在你回环安装后立即进入更新的内核。 I chose to put the boot kernel's complete init in initramfs, along with busybox and kexec (both statically linked), and my init was a simple shell script that I wrote. 我选择将启动内核的完整init放在initramfs中,以及busybox和kexec(两者都是静态链接的),而我的init是我写的一个简单的shell脚本。
  • One or more "main OS" root file systems exist on an "OS image" file system as disk image files. 一个或多个“主OS”根文件系统作为磁盘映像文件存在于“OS映像”文件系统上。 The boot kernel chooses one of these based on a versions.conf file. 引导内核根据versions.conf文件选择其中一个。 I only maintain two main OS image files, the current and fall-back file. 我只维护两个主要的OS映像文件,即当前和后备文件。 If the current one fails (more on failure detection later), then the boot kernel boots the fall-back. 如果当前的一个失败(稍后更多的故障检测),则启动内核启动回退。 If both fail or there is no fall-back, the boot kernel provides a shell. 如果两者都失败或没有回退,则启动内核提供shell。
  • System config is on a separate partition. 系统配置位于单独的分区上。 This normally isn't upgraded, but there's no reason it couldn't be. 这通常不升级,但没有理由不能升级。
  • There are four total partitions: boot, OS image, config, and data. 总共有四个分区:启动,操作系统映像,配置和数据。 The data partition is for user application stuff that is intended for frequent writing. 数据分区用于用于频繁写入的用户应用程序。 boot is never mounted read/write. boot永远不会挂载读/写。 OS image is only (re-)mounted read/write during upgrades. 在升级期间,OS映像仅(重新)安装读/写。 config is only mounted read/write when config stuff needs to change (hopefully never). 配置只需要更改(希望永远不会)配置只读装载。 data is always mounted read/write. 数据总是挂载读/写。
  • The disk image files each contain a full Linux system, including a kernel, init scripts, user programs (eg busybox, product applications), and a default config that is copied to the config partition on the first boot. 每个磁盘映像文件都包含一个完整的Linux系统,包括内核,init脚本,用户程序(例如busybox,产品应用程序),以及在第一次启动时复制到配置分区的默认配置。 The files are whatever size is necessary to fit everything in them. 文件是适合其中所有内容所需的任何大小。 As long I allowed enough room for growth so that the OS image partition is always big enough to fit three main OS image files (during an upgrade, I don't delete the old fall-back until the new one is extracted), I can allow for the main OS image to grow as needed. 只要我有足够的增长空间,以便操作系统映像分区总是足够大,以适应三个主要的操作系统映像文件(在升级过程中,我不会删除旧的后备,直到新的提取后),我可以允许主OS映像根据需要增长。 These image files are always (loop-back) mounted read-only. 这些图像文件始终以只读方式挂载(环回)。 Using these files also takes out the pain of dealing with failures of upgrading individual files within a rootfs. 使用这些文件还可以解决在rootfs中处理升级单个文件失败的麻烦。
  • Upgrades are done by transferring a self-extracting tarball to a tmpfs. 升级是通过将自解压tarball转移到tmpfs来完成的。 The beginning of this script remounts the OS image read/write, then extracts the new main OS image to the OS image file system, and then updates the versions.conf file (using the rename method described in the "murphy" paper). 该脚本的开头重新安装OS映像读/写,然后将新的主OS映像提取到OS映像文件系统,然后更新versions.conf文件(使用“murphy”文件中描述的重命名方法)。 After this is done, I touch a stamp file indicating an upgrade has happened, then reboot. 完成此操作后,我触摸一个标记文件,指示已经发生升级,然后重新启动。
  • The boot kernel looks for this stamp file. 引导内核查找此戳记文件。 If it finds it, it moves it to another stamp file, then boots the new main OS image file. 如果找到它,它会将其移动到另一个戳文件,然后引导新的主OS映像文件。 The main OS image file is expected to remove the stamp file when it starts successfully. 主OS映像文件在成功启动时会删除戳文件。 If it doesn't, the watchdog will trigger a reboot, and then the boot kernel will see this and detect a failure. 如果没有,监视程序将触发重新启动,然后启动内核将看到此情况并检测到故障。
  • You will note there are a few possible points of failure during an upgrade: syncing the versions.conf during the upgrade, and touching/removing the stamp files (three instances). 您将注意到升级过程中可能存在一些故障点:在升级期间同步versions.conf,以及触摸/删除戳记文件(三个实例)。 I couldn't find a way to reduce these further and achieve everything I wanted. 我找不到办法进一步减少这些并实现我想要的一切。 If anyone has a better suggestion, I'd love to hear it. 如果有人有更好的建议,我很乐意听到。 File system errors or power failures while writing the OS image could also occur, but I'm hoping the ext3 file system will provide some chance of surviving in that case. 编写操作系统映像时也可能出现文件系统错误或电源故障,但我希望ext3文件系统在这种情况下可以提供一些生存机会。

You can have a seperate partition for update(Say Side1/Side2). 您可以有一个单独的分区进行更新(Say Side1 / Side2)。 The existing kernel,rootfs is in Side1, then put the update in Side2 and switch. 现有的内核,rootfs在Side1中,然后将更新放在Side2中并切换。 By this you can reduce wear leveling and increase the life but the device gets costlier. 通过这种方式,您可以减少磨损均衡并延长使用寿命,但设备成本更高。

You can quick format the partitions before extracting the tar files. 您可以在提取tar文件之前快速格式化分区。 Or go with the image solution but use the smallest possible image and after dd do a filesystem resize (although that is not necessary for readonly storage) 或者使用图像解决方案,但使用尽可能小的图像,并在dd后重新调整文件系统(尽管这对于只读存储不是必需的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为window构建一个基于linux的程序? - how to build a linux-based program for window? 在基于 Linux 的发行版上签署 Windows 应用程序 - Signing Windows application on Linux-based distros 通过调制解调器连接到基于 Linux 的服务器 - Connecting to a Linux-based server over a modem 基于Linux的域管理解决方案? - Linux-based solution for domain management? 基于Linux的RDBMS,用于偶尔连接的复制 - Linux-based RDBMS for Occasionally Connected Replication 有没有办法在基于Linux的操作系统中确定复制到X剪贴板的文本来源? - Is there a way in Linux-based operating systems to determine the source of text copied to the X clipboard? 如何在Docker Hub中过滤基于Windows或Linux的容器? - How can I filter on Windows-based or Linux-based containers within Docker Hub? 如何提高在 Windows 10 上运行 R 脚本的基于 Linux 的 Docker 桌面容器的性能? - How can I improve the performance of Linux-based Docker Desktop containers running R scripts on Windows 10? 将Oulook / Exchange任务与基于Linux的Rails集成 - Integrating Oulook/Exchange Tasks with Linux-based Rails 基于 Linux 的系统上类似 Dropbox 的自动文件版本控制 - Dropbox-like automatic file versioning on Linux-based systems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM