Translated

This commit is contained in:
2021-11-20 08:17:15 +08:00 committed by GitHub
parent f3e5dab634
commit e7c7b11903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 154 additions and 155 deletions

View File

@ -1,155 +0,0 @@
[#]: subject: (How to use FreeDOS as an embedded system)
[#]: via: (https://opensource.com/article/21/6/freedos-embedded-system)
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
How to use FreeDOS as an embedded system
======
Many embedded systems today run on Linux. But once upon a time, embedded
systems either ran on a custom, proprietary platform or ran on DOS.
![Computer laptop in space][1]
The [FreeDOS website][2] says that most people use FreeDOS for three main tasks:
1. Playing classic DOS games
2. Running legacy DOS software
3. Running an embedded system
But what does it mean to run an "embedded" system?
An embedded system is basically a very minimal system that is dedicated to run a specific task. You might think of embedded systems today as part of the _Internet of Things_ (IoT) including sensors, thermostats, and doorbell cameras. Many embedded systems today run on Linux.
But once upon a time, embedded systems either ran on a custom, proprietary platform or ran on DOS. Some of these DOS-based embedded systems still run today, such as cash registers or phone private branch exchange (PBX) systems. In one example as recently as 2017, trainspotters discovered a Russian electric train control system (Russian: _САВПЭ_) running FreeDOS with special software to control and monitor the route of suburban trains and to make passenger announcements.
Setting up an embedded system on DOS requires defining a minimal DOS environment that runs a single application. Fortunately, setting up a minimal FreeDOS environment is pretty easy. Technically, all you need to boot FreeDOS and run DOS applications is the kernel and a `FDCONFIG.SYS` configuration file.
### Installing a minimal system
We can simulate a dedicated, minimal FreeDOS system by using the QEMU emulator with very small allocations. To reflect an embedded system more accurately, I'll define a virtual machine with only 8 megabytes of memory and a mere 2 megabytes for a virtual hard drive.
To create the tiny virtual hard drive, I'll use this `qemu-img` command to define a 2-megabyte file:
```
$ qemu-img create tiny.img 2M
Formatting 'tiny.img', fmt=raw size=2097152
```
This command line defines a 32-bit "i386" CPU with 8 megabytes of memory, using the 2-megabyte `tiny.img` file as the hard drive image and the FreeDOS 1.3 RC4 LiveCD as the CD-ROM media. We'll also set the machine to boot from the CD-ROM drive (`-boot order=d`) although we only need that to install. We'll boot the completed embedded system from the hard disk after we've set everything up:
```
qemu-system-i386 -m 8 -hda tiny.img -cdrom FD13LIVE.iso -boot order=d
```
Boot the system using the "Live Environment mode"—this provides us with a running FreeDOS system that we can use to transfer a minimal FreeDOS to the hard disk.
![embedded setup][3]
Boot into the LiveCD environment
(Jim Hall, [CC-BY SA 4.0][4])
We'll need to create a partition on the virtual hard drive for our programs. To do that, run the FDISK program from the command line. FDISK is the standard _fixed disk_ utility on FreeDOS. Use FDISK to create a single hard drive partition that spans the entire (2-megabyte) hard drive.
![embedded setup][5]
FDISK, after creating the 2 megabyte partition
(Jim Hall, [CC-BY SA 4.0][4])
But FreeDOS won't see the new hard drive partition until you reboot—FreeDOS only reads the hard disk details at startup. Exit FDISK and reboot, and you'll be ready for the next step.
After rebooting, you need to create a DOS filesystem on the new hard drive. Since there's just the one virtual hard disk, FreeDOS will identify it as the `C:` drive. You can create a DOS filesystem on `C:` with the FORMAT command. The `/S` option transfers the operating system files (the kernel, plus a copy of the `COMMAND.COM` shell) to the new drive.
![embedded setup][6]
Format the new drive to create a DOS filesystem
(Jim Hall, [CC-BY SA 4.0][4])
 
Now that you've created the drive and formatted it, you can install the application that will run on the embedded system.
### Installing the dedicated application
An embedded system is really just a single-purpose application running on a dedicated system. Such applications are usually custom-built for the system it will control, such as a cash register, display terminal, or control environment. For this demonstration, let's use a program from the FreeDOS 1.3 RC4 installation CD-ROM. It needs to be small enough to fit in the tiny 2-megabyte hard drive we've created for it. This can be anything—so just for fun, let's make it a game.
FreeDOS 1.3 RC4 includes several fun games. One game that I like is a board game called Simple Senet. It's based on Senet, an ancient Egyptian board game. The details of the game aren't important for this demonstration, except that we'll install it and set it up as the dedicated application for the embedded system.
To install the application, go into the `\PACKAGES\GAMES` directory on the FreeDOS 1.3 RC4 LiveCD. You'll see a long list of packages there, and the one we want is `SENET.ZIP`.
![embedded setup][7]
A list of game packages from FreeDOS 1.3 RC4
(Jim Hall, [CC-BY SA 4.0][4])
To unzip the Simple Senet package onto the virtual hard drive, use the `UNZIP` command. All FreeDOS packages are Zip files, so you can use any Zip-compatible archive utility to manage them. FreeDOS 1.3 RC4 includes `ZIP` to create Zip archives, and `UNZIP` to extract Zip archives. Both are from the [Info-Zip Project][8].
```
`UNZIP SENET.ZIP -d C:\FDOS`
```
Normally, using `UNZIP` will extract a Zip file in the current directory. The `-d C:\FDOS` option at the end of the command line tells `UNZIP` to extract the Zip file to the `C:\FDOS` directory. (`-d` means "destination.")
![embedded setup][9]
Unzipping the Simple Senet game
(Jim Hall, [CC-BY SA 4.0][4])
To run the Simple Senet game whenever the embedded system boots, we need to tell FreeDOS to use Senet as the system "shell." The default FreeDOS shell is the `COMMAND.COM` program, but you can define a different shell program using the `SHELL=` directive in the `FDCONFIG.SYS` kernel configuration file. We can use FreeDOS Edit to create the new `C:\FDCONFIG.SYS` file.
![Embedded edit senet][10]
(Jim Hall, [CC-BY SA 4.0][4])
If you need to define other parameters to support the embedded system, you can add those to the `FDCONFIG.SYS` file. For example, you might need to set environment variables using the `SET` action, or tune the FreeDOS kernel with `FILES=` or `BUFFERS=` statements.
### Run the embedded system
With the embedded system fully defined, we can now reboot the machine to run the embedded application. Running an embedded system usually requires only limited resources, so for this demonstration, we'll tweak the QEMU command line to only boot from the hard drive (`-boot order=c`) and not define a CD-ROM drive:
```
qemu-system-i386 -m 8 -hda tiny.img -boot order=c
```
When the FreeDOS kernel starts up, it reads the `FDCONFIG.SYS` file for its startup parameters. Then it runs the shell using the `SHELL=` line. That runs the Simple Senet game automatically.
![embedded setup][11]
Running Simple Senet as an embedded system
(Jim Hall, [CC-BY SA 4.0][4])
We've used Simple Senet to demonstrate how to set up an embedded system on FreeDOS. Depending on your needs, you can use whatever standalone application you like. Define it as the DOS shell using the `SHELL=` line in `FDCONFIG.SYS` and FreeDOS will automatically launch the application at boot-time.
However, there's one limitation here. Embedded systems do not usually need to exit back to a command prompt, so these dedicated applications don't usually allow the user to quit to DOS. If you manage to exit the embedded application, you'll likely see a "Bad or missing Command Interpreter" prompt, where you'll need to enter the full path to a new shell. For a user-focused desktop system, this would be a problem. But on an embedded system that's dedicated to doing only one job, you should never need to exit anyway.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/6/freedos-embedded-system
作者:[Jim Hall][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jim-hall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_space_graphic_cosmic.png?itok=wu493YbB (Computer laptop in space)
[2]: https://www.freedos.org/
[3]: https://opensource.com/sites/default/files/uploads/embedded-setup02.png (Boot into the LiveCD environment)
[4]: https://creativecommons.org/licenses/by-sa/4.0/
[5]: https://opensource.com/sites/default/files/uploads/embedded-setup09.png (FDISK, after creating the 2 megabyte partition)
[6]: https://opensource.com/sites/default/files/uploads/embedded-setup19.png (Format the new drive to create a DOS filesystem)
[7]: https://opensource.com/sites/default/files/uploads/games-dir.png (A list of game packages from FreeDOS 1.3 RC4)
[8]: http://infozip.sourceforge.net/
[9]: https://opensource.com/sites/default/files/uploads/senet-unzip.png (Unzipping the Simple Senet game)
[10]: https://opensource.com/sites/default/files/pictures/embedded-edit-senet.png (Embedded edit senet)
[11]: https://opensource.com/sites/default/files/uploads/senet.png (Running Simple Senet as an embedded system)

View File

@ -0,0 +1,154 @@
[#]: subject: (How to use FreeDOS as an embedded system)
[#]: via: (https://opensource.com/article/21/6/freedos-embedded-system)
[#]: author: (Jim Hall https://opensource.com/users/jim-hall)
[#]: collector: (lujun9972)
[#]: translator: (robsean)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
如果将 FreeDOS 作为嵌入式系统使用
======
现在,很多嵌入式系统都是在 Linux 上运行的。但是,在很久很久以前,嵌入式系统要么在一个定制的专有的平台上运行,要么在 DOS 上运行。
![Computer laptop in space][1]
[FreeDOS 网站][2] 宣称,大多数人使用 FreeDOS 来完成三项主要的活动:
1. 玩经典的 DOS 游戏
2. 运行传统的 DOS 软件
3. 运行一款嵌入式系统
但是,运行一个"嵌入式"系统的意义是什么呢?
一个嵌入式系统基本上是一款非常小的系统,专用于运行一个特定的任务。你可以把现在的嵌入式系统当作是 _物联网_ (IoT) 的一部分,包含传感器,恒温器,和门铃摄像头。现在,很多嵌入式系统都是在 Linux 上运行的。
但是,在很久很久以前,嵌入式系统要么在一个定制的专有的平台上运行,要么在 DOS 系统上运行。在现在,一些基于 DOS 的嵌入式系统仍然在运行,例如,收银机或电话专用交换机 (PBX) 系统。举个例子来说在2017年酷爱列车的人发现一个正在运行 FreeDOS 的俄罗斯的电动列车控制系统 (Russian: _САВПЭ_) ,它使用特殊的软件来控制和监控郊区列车的线路,并发布乘客通告。
在 DOS 上设置一个嵌入式系统需要定义一个运行单个应用程序的最小的 DOS 环境。幸运的是,设置一个最小的 FreeDOS 环境是非常容易的。从技术上来说,启动 FreeDOS 和运行 DOS 应用程序仅需要内核和一个 `FDCONFIG.SYS` 配置文件
### 安装一款最小的系统
我们可以使用 QEMU 仿真器来模拟一个专用的最小的 FreeDOS 系统,它带有非常小的配置。为了更准确地反映一个嵌入式系统,我将定义一个只有 8 MB 的存储器和仅仅有 2 MB 的硬盘驱动器的虚拟机。
为创建极微型虚拟硬盘,我将使用这个 `qemu-img` 命令来定义一个 2M 的文件:
```
$ qemu-img create tiny.img 2M
Formatting 'tiny.img', fmt=raw size=2097152
```
下面的这行命令定义了一个32位的 "i386" CPU 8MB 的存储器,使用 2MB 的 `tiny.img` 文件作为硬盘驱动器镜像,使用 FreeDOS 1.3 RC4 LiveCD 作为 CD-ROM 介质。我们也将设置机器从 CD-ROM 驱动器启动 (`-boot order=d`) ,尽管我们只需要用来安装。在我们完成所有的设置后,我们将从该硬盘启动完整的嵌入式系统:
```
qemu-system-i386 -m 8 -hda tiny.img -cdrom FD13LIVE.iso -boot order=d
```
使用 "Live Environment mode" 来启动系统—这将为我们提供一个正在运行的 FreeDOS 系统,我们可以使用它来将一个最小的 FreeDOS 转移到硬盘上。
![embedded setup][3]
启动到 LiveCD 环境之中
(Jim Hall, [CC-BY SA 4.0][4])
我们需要在虚拟硬盘驱动器上为我们的程序创建一个分区。为此,从命令行中运行 FDISK 程序。FDISK 是 FreeDOS 上的一个标准的 _安排磁盘_ 实用程序。使用 FDISK 来创建一个单个硬盘驱动器分区,贯穿整个 (2-MB) 硬盘驱动器。
![embedded setup][5]
FDISK在创建 2 MB 分区后
(Jim Hall, [CC-BY SA 4.0][4])
但是,在你重新启动 FreeDOS 之前FreeDOS 将不会看到新的硬盘驱动器分区— FreeDOS 仅在启动时读取硬盘详细信息。退出 FDISK ,并重新启动 FreeDOS 。
在重新启动后,你需要在新的硬盘驱动器上创建一个 DOS 文件系统。因为这里只有一个虚拟硬盘FreeDOS 将识别其为 `C:` 驱动器。你可以使用 FORMAT 命令来在 `C:` 驱动器上创建一个 DOS 文件系统。使用 `/S` 选项将把操作系统文件 (内核,外加一个 `COMMAND.COM` shell 的副本) 转移到新的驱动器上。
![embedded setup][6]
格式化新的驱动器来创建一个 DOS 文件系统
(Jim Hall, [CC-BY SA 4.0][4])
 
你已经创建了硬盘驱动器并将其格式化,现在,你可以安装应用程序,这些应用程序是将会在新安装的嵌入式系统上运行的。
### 安装专用的应用程序
嵌入式系统实际上只是一个运行在一个专用系统上的单一用途的应用程序。这些应用程序通常是为其将要控制的系统所自定义构建的,例如,一台收银机,显示终端,或控制环境。在这个演示中,让我们使用一个来自 FreeDOS 1.3 RC4 安装 CD-ROM 中的程序。它需要足够小,以适应我们为其创建的 2 MB 极微硬盘驱动器。这可以是任何东西—所以,为了好玩,让我们把它变成一个游戏。
FreeDOS 1.3 RC4 包含一些有趣的游戏。我喜欢的一个游戏是一个名称为 Simple Senet 的棋类游戏。它是一个基于 Senet 的古埃及棋类游戏。游戏的细节对这个演示并不重要,我们将安装它,并将其设置为嵌入式系统的专业应用程序。
为安装应用程序,在 FreeDOS 1.3 RC4 LiveCD 上,进入 `\PACKAGES\GAMES` 目录。你将在其中看到一个很长的软件包列表,而我们想要的 `SENET.ZIP`
![embedded setup][7]
来自 FreeDOS 1.3 RC4 的一个游戏软件包列表
(Jim Hall, [CC-BY SA 4.0][4])
为解压缩 Simple Senet 软件包到虚拟硬盘上,使用 `UNZIP` 命令。所有的 FreeDOS 软件包都是 Zip 文件,因此,你可以使用任意与 Zip 兼容的档案实用程序来管理它们。FreeeDOS 1.3 RC4 包含创建 Zip 档案文件的 `ZIP` ,和提取 Zip 档案文件的 `UNZIP` 。它们都来自 [Info-Zip 项目][8] 。
```
`UNZIP SENET.ZIP -d C:\FDOS`
```
通常,使用 `UNZIP` 来提取 Zip 文件到当前目录中。在命令行结尾的 `-d C:\FDOS` 选项将告诉 `UNZIP` 来提取 Zip 文件到 `C:\FDOS` 目录之中。(`-d` 意味着 "目的地")
![embedded setup][9]
解压缩 Simple Senet 游戏
(Jim Hall, [CC-BY SA 4.0][4])
我在嵌入式系统启动时运行 Simple Senet 游戏,我们需要告诉 FreeDOS 来使用 Senet 作为系统的 "shell" 。 默认的 FreeDOS 的 shell 是 `COMMAND.COM` 程序,但是,你可以在 `FDCONFIG.SYS` 内核配置文件中使用 `SHELL=` 指令来定义一个不同的 shell 程序。我们可以使用 FreeDOS 的 Edit 来创建新的 `C:\FDCONFIG.SYS` 文件。
![Embedded edit senet][10]
(Jim Hall, [CC-BY SA 4.0][4])
如果你需要定义其它的参数来支持嵌入式系统,你可以将其添加到 `FDCONFIG.SYS` 文件之中。例如,你可能需要使用 `SET` 动作来设置环境变量,或者使用 `FILES=` 或 `BUFFERS=` 语句来调整 FreeDOS 内核。
### 运行嵌入式系统
在全面地完成嵌入式系统的定义之后,现在,我们可以重新启动计算机来运行嵌入式应用程序。运行一个嵌入式系统通常仅需要有限的资源,因此,在这个演示中,我们只需要调整 QEMU 命令行来从硬盘驱动器 (`-boot order=c`) 重启动,而不再定义一个 CD-ROM 驱动器:
```
qemu-system-i386 -m 8 -hda tiny.img -boot order=c
```
当 FreeDOS 内核启动时,它将读取 `FDCONFIG.SYS` 文件一获取启动参数。然后,它将使用 `SHELL=` 行的定义来运行 shell 。这将自动地运行 Simple Senet 游戏。
![embedded setup][11]
作为一个嵌入式系统运行 Simple Senet
(Jim Hall, [CC-BY SA 4.0][4])
我们已经使用了 Simple Senet 来演示如何在 FreeDOS 上设置一个嵌入式系统。取决于你的需要,你可以使用任何你喜欢的独立的应用程序。在 `FDCONFIG.SYS` 中使用 `SHELL=` 行将其定义为 DOS 的 shell FreeDOS 将在启动时自动地启动该应用程序。
不过,在这里有一个限制。嵌入式系统通常不需要退回到一个命令行提示符之中,因此这些专用应用程序通常不运行用户退出到 DOS 之中。如果你设法退出了嵌入式应用程序,你可能会看到一个 "Bad or missing Command Interpreter" 的提示,你将需要在其中输入一个新的 shell 的完整路径。对于一个以用户为中心的桌面系统来说,这将是一个问题。但是在一个嵌入式系统上,它只专注执行一种工作的,那么,你也永远不需要退出嵌入式应用程序。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/6/freedos-embedded-system
作者:[Jim Hall][a]
选题:[lujun9972][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jim-hall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/computer_space_graphic_cosmic.png?itok=wu493YbB (Computer laptop in space)
[2]: https://www.freedos.org/
[3]: https://opensource.com/sites/default/files/uploads/embedded-setup02.png (Boot into the LiveCD environment)
[4]: https://creativecommons.org/licenses/by-sa/4.0/
[5]: https://opensource.com/sites/default/files/uploads/embedded-setup09.png (FDISK, after creating the 2 megabyte partition)
[6]: https://opensource.com/sites/default/files/uploads/embedded-setup19.png (Format the new drive to create a DOS filesystem)
[7]: https://opensource.com/sites/default/files/uploads/games-dir.png (A list of game packages from FreeDOS 1.3 RC4)
[8]: http://infozip.sourceforge.net/
[9]: https://opensource.com/sites/default/files/uploads/senet-unzip.png (Unzipping the Simple Senet game)
[10]: https://opensource.com/sites/default/files/pictures/embedded-edit-senet.png (Embedded edit senet)
[11]: https://opensource.com/sites/default/files/uploads/senet.png (Running Simple Senet as an embedded system)